Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

03 gui 04

435 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

03 gui 04

  1. 1. GUI Applications Development Using .NET FrameworkObjectives In this session, you will learn to: Validate user input using controls and events Work with the CommonDialog class Create a custom dialog box Ver. 1.0 Session 4 Slide 1 of 25
  2. 2. GUI Applications Development Using .NET FrameworkValidation of User Inputs Validation is a means to check the accuracy and correctness of the data entered by a user in an application. By performing validation, you can prompt the user to enter correct data and therefore, reduce errors. To validate data in a control, the Validating event of that control can be used. After performing validation, the user can be prompted by an appropriate message. This message can be displayed using: MessageBox class ErrorProvider Control StatusStrip Control Let us understand how the data in the controls can be validated. Ver. 1.0 Session 4 Slide 2 of 25
  3. 3. GUI Applications Development Using .NET FrameworkJust a minute Name the event that enables the user to prevent shifting of focus from a control until all the validation rules have been met. Answer: The Validating event Ver. 1.0 Session 4 Slide 3 of 25
  4. 4. GUI Applications Development Using .NET FrameworkThe MessageBox Class • The MessageBox class is used to display informative messages to users. • For example, the following code snippet displays a message box on the click event of a button. private void button1_Click(object sender,EventArgs e) { MessageBox.Show("The entered data is not valid. Please enter valid data.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Message Box Text Ver. 1.0 Session 4 Slide 4 of 25
  5. 5. GUI Applications Development Using .NET FrameworkThe MessageBox Class (Contd.) • The MessageBox class is used to display informative messages to users. • For example, the following code snippet displays a message box on the click event of a button. private void button1_Click(object sender,EventArgs e) { MessageBox.Show("The entered data is not valid. Please enter valid data.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Message Box Title } Ver. 1.0 Session 4 Slide 5 of 25
  6. 6. GUI Applications Development Using .NET FrameworkThe MessageBox Class (Contd.) • The MessageBox class is used to display informative messages to users. • For example, the following code snippet displays a message box on the click event of a button. private void button1_Click(object sender,EventArgs e) { MessageBox.Show("The entered data is not valid. Please enter valid data.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Message Box Button Ver. 1.0 Session 4 Slide 6 of 25
  7. 7. GUI Applications Development Using .NET FrameworkThe MessageBox Class (Contd.) • The MessageBox class is used to display informative messages to users. • For example, the following code snippet displays a message box on the click event of a button. private void button1_Click(object sender,EventArgs e) { MessageBox.Show("The entered data is not valid. Please enter valid data.", "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Message Box Icon Ver. 1.0 Session 4 Slide 7 of 25
  8. 8. GUI Applications Development Using .NET FrameworkJust a minute • How many parameters are there in the Show() method of the MessageBox class? 1. One 2. Two 3. Three 4. Four Answer: 4. Four Ver. 1.0 Session 4 Slide 8 of 25
  9. 9. GUI Applications Development Using .NET FrameworkJust a minute • Which method of the MessageBox class is used to display a message in the message box? Answer: – The Show() method Ver. 1.0 Session 4 Slide 9 of 25
  10. 10. GUI Applications Development Using .NET FrameworkThe StatusStrip Control • The StatusStrip control is a container control derived from System.Windows.Forms.ToolStrip class. • This control is used to: – Display information about the objects that are on the current form. – Provide feedback on the progress of any operation being performed by the form. A StatusStrip control contains four child controls. These child controls are: StatusLabel ProgressBar DropDownButton SplitButton Ver. 1.0 Session 4 Slide 10 of 25
  11. 11. GUI Applications Development Using .NET FrameworkThe StatusStrip Control (Contd.) The following figure shows the StatusStrip control with its child controls. This control is used to display status information This control is used to show and prompt the user for a This control displays the completion status of any valid entry. ThisToolStripDropDown from control is a task. combination user standard a which a of a can select button on the left andmany single item from a items. dropdown button on the right. Ver. 1.0 Session 4 Slide 11 of 25
  12. 12. GUI Applications Development Using .NET FrameworkJust a minute Which of the following position is the default docking position of the StatusStrip control on the form? 1. Left 2. Right 3. Top 4. Bottom Answer: 4. Bottom Ver. 1.0 Session 4 Slide 12 of 25
  13. 13. GUI Applications Development Using .NET FrameworkJust a minute Which property of the ProgressBar control specifies the amount to increment the current value of the control? 1. Minimum 2. Maximum 3. Value 4. Step Answer: 4. Step Ver. 1.0 Session 4 Slide 13 of 25
  14. 14. GUI Applications Development Using .NET FrameworkThe ErrorProvider Control The ErrorProvider control can be used to display an error message, whenever the user positions the mouse pointer over the error icon. This error icon is displayed next to the control in which the user has entered invalid data. The following figure displays an ErrorProvider control attached to a text box on the form. ErrorProvider Control Ver. 1.0 Session 4 Slide 14 of 25
  15. 15. GUI Applications Development Using .NET FrameworkJust a minute Which property of the ErrorProvider control automatically sets to the form to which it is added? 1. SetError 2. ContainerControl 3. Error on errorProviderControlName 4. BlinkStyle Answer: 2. ContainerControl Ver. 1.0 Session 4 Slide 15 of 25
  16. 16. GUI Applications Development Using .NET FrameworkDemo: Validating Data Problem Statement: SigmaCom is a telecommunication company which is developing software that would gather information about its employees. The company requires that the information entered should be correct and all the fields should be filled with required data and that no fields are left blank. Help the company to develop the required application. Ver. 1.0 Session 4 Slide 16 of 25
  17. 17. GUI Applications Development Using .NET FrameworkDemo: Validating Data (Contd.) Solution: To meet the preceding requirement, you need to perform the following tasks: 1. Create a new VC# application. 2. Design the Employee Information form. 3. Add code to perform the desired tasks. 4. Execute the application and verify the output. Ver. 1.0 Session 4 Slide 17 of 25
  18. 18. GUI Applications Development Using .NET FrameworkIntroducing CommonDialog Classes • In VC#, the CommonDialog class is the base class for displaying common dialog boxes such as font dialog box, open dialog box, and save dialog box. Ver. 1.0 Session 4 Slide 18 of 25
  19. 19. GUI Applications Development Using .NET FrameworkTypes of CommonDialog Classes • There are various classes that are inherited from the CommonDialog class. These are: ColorDialog class FontDialog class FileDialog class OpenFileDialog class SaveFileDialog class FolderBrowserDialog class PrintDialog class Let us understand how these dialog boxes work. Ver. 1.0 Session 4 Slide 19 of 25
  20. 20. GUI Applications Development Using .NET FrameworkCreating Custom Dialog Box In VC#, the user can create customized dialog boxes in order to perform some specific tasks. The Windows Forms Designer can be used for creating a custom dialog box with the following changes: – Assign a value of FixedDialog to the FormBorderStyle property of the form. – Assign a value of False to the ControlBox, MinimizeBox, and MaximizeBox properties of the form. – Assign an appropriate value to the DialogResult property for each button used on the form. Ver. 1.0 Session 4 Slide 20 of 25
  21. 21. GUI Applications Development Using .NET FrameworkJust a minute All the classes that inherit from the CommonDialog class override the ___________ method to create a specific dialog box. Answer: RunDialog() Ver. 1.0 Session 4 Slide 21 of 25
  22. 22. GUI Applications Development Using .NET FrameworkDemo: Creating Custom Dialog Box Problem Statement: Create an application that would accept the user input into a rich text box control. The application should have a Zoom button. This button should invoke a custom dialog box, which should accept a numeric value from a user. Whatever value is passed through the dialog box, the text in the rich text box control should get enlarged by that percentage. Ver. 1.0 Session 4 Slide 22 of 25
  23. 23. GUI Applications Development Using .NET FrameworkDemo: Creating Custom Dialog Box (Contd.) Solution: To create the application, you need to perform the following tasks: 1. Create a new VC# application. 2. Design the main form. 3. Design a custom dialog box. 4. Add code in the custom dialog box. 5. Add code in the main form. 6. Execute the application and verify the output. Ver. 1.0 Session 4 Slide 23 of 25
  24. 24. GUI Applications Development Using .NET FrameworkSummary In this session, you learned that: – Validation is a means to check the accuracy and the correctness of the data entered by the user. – The Validating event enables you to prevent the user from shifting the focus from the control being validated to some other control on the form until all validation rules have been met. – The MessageBox class is used to display prompts and messages on the screen. After closing the message box the user cannot see the message. – An instance of the MessageBox class cannot be created by using the new keyword. – The StatusStrip control is derived from System.Windows.Forms.ToolStrip class. It is a container control that can hold other controls. Ver. 1.0 Session 4 Slide 24 of 25
  25. 25. GUI Applications Development Using .NET FrameworkSummary (Contd.) The StatusStrip control contains four types of controls. The controls are: • StatusLabel • ProgressBar • DropDownButton • SplitButton – The ErrorProvider control is used to display an error message, whenever the user positions the mouse pointer over the error icon. – The CommonDialog class is the base class for the most commonly used dialog boxes, such as, Color, Font, File, FolderBrowser, Print, and Page Setup. – A Custom dialog box can be created by setting some properties of the Windows Form such as, FormBorderStyle, ControlBox, MinimizeBox, and MaximizeBox. Ver. 1.0 Session 4 Slide 25 of 25

×