1. GUI Applications Development Using .NET Framework
Objectives
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. GUI Applications Development Using .NET Framework
Validation 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
The 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
Demo: 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. GUI Applications Development Using .NET Framework
Demo: 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. GUI Applications Development Using .NET Framework
Introducing 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. GUI Applications Development Using .NET Framework
Types 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. GUI Applications Development Using .NET Framework
Creating 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. GUI Applications Development Using .NET Framework
Just 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. GUI Applications Development Using .NET Framework
Demo: 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. GUI Applications Development Using .NET Framework
Demo: 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. GUI Applications Development Using .NET Framework
Summary
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. GUI Applications Development Using .NET Framework
Summary (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
Editor's Notes
Start the session by sharing the session objectives with the students.
The faculty must explain to the students that validation is a very important and useful feature that can be added in Windows Form. Validation helps to ensure that the data entered by the users is accurate and as desired. Let us understand the concept of Validation with the help of an example. While entering student’s marks, the faculty must ensure that the marks entered within the text box are in the range 0-100. Also, the code should ensure that the faculty is restricted from entering text or special characters in the marks text box. If a faculty enters a value such as -5, 113, or ab!, it will be considered as invalid and it should not be allowed also. Therefore, code can be written to ensure that the faculty enters data only within the specified range. The faculty must prepare and present a demo to show that the data within the controls can be validated. Again you can take the simple example of an addition form. In this form if the user enters text or special characters in place of number, then an error should be raised.
Reiterate the concepts taught earlier by asking the given question.
Using the slide 4 th , 5 th 6 th, and 7 th , discuss with the students that while validating data, it is essential that proper messages should be displayed in order to specify that the user has entered invalid data. These messages can be displayed using MessageBox class. Discuss the Show() method of this class that is actually used to display messages. Discuss the parameters that can be used with this method to customize the appearance of the box that appears. You can also display a small example that shows the use of MessageBox.
Reiterate the concepts taught earlier by asking the given question.
Reiterate the concepts taught earlier by asking the given question.
Using this slide and the next slide, the faculty should discuss the purpose and features of the StatusStrip control. This control should be used to specify messages that can help the user identify the correct data to be entered by the user. In addition, it provides other features also. The faculty must demonstrate an application with this control.
The faculty must discuss the following properties of the StatusStrip Control: Items LayoutStyle Dock
Reiterate the concepts taught earlier by asking the given question.
Reiterate the concepts taught earlier by asking the given question.
Using this slide, the faculty can explain the purpose of the ErrorProvider control. The faculty must explain that this control helps to highlight the error as well as specifies the control that has generated the error. The faculty must discuss the properties and methods of ErrorProvider control given in the SG.
Reiterate the concepts taught earlier by asking the given question.
Conduct the activity stated in the slide in a collaborative mode in the class.
The faculty must explain the Common dialog boxes available in Windows.
The faculty must present a demo on the working of some of these dialog boxes. The faculty can prepare a form with different buttons, each for a different dialog box. The faculty can use the code within the Student’s Guide to present the demo.
The faculty can use this slide to explain the purpose of Custom Dialog Box. In addition, the faculty can tell the students that they can use this when they need to design their own dialog box. For example, in some application if the students need to connect to several databases regularly then in place of writing the code again and again, the user can create a custom open dialog box that accepts the name of the database and opens it up.
Reiterate the concepts taught earlier by asking the given question.
Conduct the activity stated in the slide in a collaborative mode in the class.
You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.
You can summarize the session by running through the summary given in SG. In addition, you can also ask students summarize what they have learnt in this session.