1. GUI Applications Development Using .NET Framework
Objectives
In this session, you will learn to:
Work with menus and multiple-document interface applications
Implement the ToolStrip Control in multiple-document interface
applications
Identify the functionality of print components
Ver. 1.0 Session 5 Slide 1 of 35
2. GUI Applications Development Using .NET Framework
Working with Menus
VC# enables you to create menus and multiple-document
interface (MDI) applications.
In the Windows environment, you can use menus to
enhance the user interface of an application.
In VC#, you can create two types of menus:
The menus that appear on the menu bar
Context menus, which appear when the right mouse button is
clicked
Context menu items can also
You can add menu either at VC#
To added to a items items to a time:
be add menu form at design
run time:
design timeeither rundesign time or at
or at at time.
applicationthe MenuStrip control from the run
1. Add
time. Toolbox.at design time.
Toolbox
To add context menu for a
control or a code toyou need to
2. Write form, programmaticallyusing
Append individual menu items add
add the ContextMenuStrip
ToolStripMenuItem
the Menu Designer.objects to the
control from the object. to
MenuStrip Toolbox
the form.
Ver. 1.0 Session 5 Slide 2 of 35
3. GUI Applications Development Using .NET Framework
Working with MDI Applications
• In VC#, an MDI application consists of two parts, an MDI
parent form and the MDI child form.
• An MDI parent form is the form that contains all the MDI
child forms.
• An MDI parent form can have multiple MDI child forms, but
it cannot be a MDI child form to another MDI parent form
simultaneously.
• An MDI parent form can be created either at design time or
at run time by setting the IsMdiContainer property of the
form to true.
Ver. 1.0 Session 5 Slide 3 of 35
4. GUI Applications Development Using .NET Framework
Working with MDI Applications (Contd.)
Windows application allows a user to open more than one
file at a time.
Whenever a user opens multiple files, he/she may need to
arrange all the files on the screen in order to work
efficiently.
To arrange the opened child forms in the MDI parent form,
you need to write the following code:
this.LayoutMdi(MdiLayout.TileVertical); // This code
will arrange all
the opened
child windows
in a vertically
tiled position.
Ver. 1.0 Session 5 Slide 4 of 35
5. GUI Applications Development Using .NET Framework
Working with MDI Applications (Contd.)
Windows application allows a user to open more than one
file at a time.
Whenever a user opens multiple files, he/she may need to
arrange all the files on the screen in order to work
efficiently.
To arrange the opened child forms in the MDI parent form,
you need to write the following code:
this.LayoutMdi(MdiLayout.TileVertical);
// Refers to the
MDIParent form.
Ver. 1.0 Session 5 Slide 5 of 35
6. GUI Applications Development Using .NET Framework
Working with MDI Applications (Contd.)
Windows application allows a user to open more than one
file at a time.
Whenever a user opens multiple files, he/she may need to
arrange all the files on the screen in order to work
efficiently.
To arrange the opened child forms in the MDI parent form,
you need to write the following code:
this.LayoutMdi(MdiLayout.TileVertical);
// Is a method,
which takes
MdiLayout values
as an argument.
Ver. 1.0 Session 5 Slide 6 of 35
7. GUI Applications Development Using .NET Framework
Working with MDI Applications (Contd.)
Windows application allows a user to open more than one
file at a time.
Whenever a user opens multiple files, he/she may need to
arrange all the files on the screen in order to work
efficiently.
To arrange the opened child forms in the MDI parent form,
you need to write the following code:
this.LayoutMdi(MdiLayout.TileVertical);
// Is the value
that arranges all
opened child
forms in vertical
direction.
Ver. 1.0 Session 5 Slide 7 of 35
8. GUI Applications Development Using .NET Framework
Working with MDI Applications (Contd.)
There are four MdiLayout values, as described in the
following table.
MdiLayout Values Description
ArrangeIcons All MDI child icons are arranged within the client region of the MDI
parent form.
Cascade All MDI child windows are cascaded within the client region of the MDI
parent form.
TileHorizontal All MDI child windows are tiled horizontally within the client region of
the MDI parent form.
TileVertical All MDI child windows are tiled vertically within the client region of the
MDI parent form.
Ver. 1.0 Session 5 Slide 8 of 35
9. GUI Applications Development Using .NET Framework
Working with MDI Applications (Contd.)
MDI applications usually have a Window menu that holds
the name of all the opened child windows.
During the creation of an MDI application, you can send
data to an active MDI child form.
Ver. 1.0 Session 5 Slide 9 of 35
10. GUI Applications Development Using .NET Framework
Just a minute
In an MDI application, you need to ensure that when the
Product menu option is clicked, the Product form is
displayed as a child form. Complete the following code that
will display the Product form:
public class ProductsFrm: Form
{
private void Product_Click(object
sender, EventArgs e)
{
Productfrm stdFrmObj = new
studentFrm();
}
Ver. 1.0 Session 5 Slide 10 of 35
11. GUI Applications Development Using .NET Framework
Just a minute (Contd.)
Answer:
public class ProductsFrm : Form
{
private void Product_Click(object sender,
EventArgs e)
{
Productfrm productFrmObj = new
studentFrm();
productFrmObj.MdiParent=this;
productFrmObj.Show
}
Ver. 1.0 Session 5 Slide 11 of 35
12. GUI Applications Development Using .NET Framework
Just a minute
You have added a ContextMenuStrip control to a form. This
control has the default name contextMenuStrip1. You have
added three ToolStripMenuItems named Product,
Customer, and Sales to contextMenuStrip1. How would you
ensure that the ToolStripMenuItems added to
ContextMenu1 would be displayed when a user right-clicks
the Windows form?
Answer:
By Setting the ContextMenuStrip property of the form to
contextMenuStrip1.
Ver. 1.0 Session 5 Slide 12 of 35
13. GUI Applications Development Using .NET Framework
Demo: Designing an MDI Application with Menu
Problem Statement:
Create a data-entry application. The application should enable
the user to enter the data in the Student Details forms. The
Student Details form should have a menu item named Print,
which should get merged with the main MDI parent form menu.
The following figure shows how you can organize the main
menu on the MDI parent:
Data Entry Forms Exit
Student Details
Faculty Details
When the user clicks the Student Details form, the Student Details
form should be displayed. When the user clicks on the Faculty
Details, a message ‘Faculty Details Menu Item Clicked’ should get
displayed. The user should be able to close the application by
clicking the Exit menu item.
Ver. 1.0 Session 5 Slide 13 of 35
14. GUI Applications Development Using .NET Framework
Demo: Designing an MDI Application with Menu (Contd.)
Solution:
To create an MDI application with menu support, you need to
perform the following tasks:
1. Create a new VC# application.
2. Convert the form to the MDI parent form.
3. Design the menu on the MDI parent form.
4. Design the Student Details entry form.
5. Create the Print menu on the Student Details entry form.
6. Add code to MDI parent form and Student Details Entry form.
7. Execute the application and verify the output.
Ver. 1.0 Session 5 Slide 14 of 35
15. GUI Applications Development Using .NET Framework
Demo: Using ContextMenuStrip Control
Problem Statement:
Modify the activity, Designing an MDI Application with Menu, to
include a context menu in the MDI parent form. The context
menu should enable the user to open a Student Details data
entry from, display the message on clicking the Faculty Details
menu item, and terminate the application on clicking the Exit
menu item.
Ver. 1.0 Session 5 Slide 15 of 35
16. GUI Applications Development Using .NET Framework
Demo: Using ContextMenuStrip Control (Contd.)
Solution:
To add the context menu to the MDI application created in the
previous activity, you need to perform the following tasks:
1. Add the context menu to the MDI parent form.
2. Add code for the context menu.
3. Execute the application and verify the output.
Ver. 1.0 Session 5 Slide 16 of 35
17. GUI Applications Development Using .NET Framework
Working with ToolStrip Control
Toolbar provides easy and quick access to the most
frequently used options.
A toolbar contains buttons that provide quick access to the
most frequently used options in an application.
In VC#, you include the toolbar facility by adding a ToolStrip
control to the Windows Form.
You can add buttons to a toolbar either at design
time or at run time.
To add buttons during design time, you do the
following:
1. Add a ToolStrip control to the Windows Form.
2. From the Properties window of the ToolStrip
control, you need to access the Items
property.
To add items at run time, you need to add a ToolStrip
control to the Windows Form, and then write code to
add items to the ToolStrip control.
Ver. 1.0 Session 5 Slide 17 of 35
18. GUI Applications Development Using .NET Framework
Just a minute
Fill in the blank:
You can add images to the ToolStrip button control by
setting the _____________________ property of the
ToolStrip button control.
Answer:
ImageIndex
Ver. 1.0 Session 5 Slide 18 of 35
19. GUI Applications Development Using .NET Framework
Demo: Using ToolStrip Control
Problem Statement:
Modify the activity, Using ContextMenuStrip Control, to include
a ToolStrip control in the MDI parent form. Design the ToolStrip
control to enable the users to:
Display the Student Details data entry form on the click of the
Student Details toolbar button.
Display the message on the click of the Faculty Details toolbar
button.
Terminate the application on the click of Exit button of the toolbar.
Ver. 1.0 Session 5 Slide 19 of 35
20. GUI Applications Development Using .NET Framework
Demo: Using ToolStrip Control (Contd.)
Solution:
To add and configure the ToolStrip control to the MDI
application, you need to perform the following tasks:
1. Add the ToolStrip control to the MDI parent form.
2. Connect the ToolStrip button event handlers to the MenuItem
event handlers.
3. Execute the application and verify the output.
Ver. 1.0 Session 5 Slide 20 of 35
21. GUI Applications Development Using .NET Framework
Introducing Print Components
There are three dialog boxes in VC# that can be used to
help in printing of text or graphics. These are:
PrintDialog control
PageSetupDialog control
PrintPreviewDialog control
Ver. 1.0 Session 5 Slide 21 of 35
22. GUI Applications Development Using .NET Framework
Printing Text and Graphics
In VC#, you can use the default Print dialog box to print any
text or graphics.
There are two ways of using the Print dialog box:
By adding PrintDialog control and the PrintDocument control to
the form.
By creating an instance of PrintDialog and
PrintDocument classes.
Let us understand how does the Print dialog box works.
Ver. 1.0 Session 5 Slide 22 of 35
23. GUI Applications Development Using .NET Framework
Just a minute
Which property is used to trap the button that a user clicks
in the Print dialog box?
1. DialogResult Property
2. Document Property
3. Filter Property
4. Tag Property
Answer:
1. DialogResult Property
Ver. 1.0 Session 5 Slide 23 of 35
24. GUI Applications Development Using .NET Framework
PageSetupDialog Class
In VC#, you can use the default Windows Page Setup
dialog box to set the page details for printing.
There are two ways of using the Page Setup dialog box:
By adding PageSetupDialog control and the PrintDocument
control to the form.
By creating an instance of PageSetupDialog and
PageSettings classes.
Let us understand how does the Page Setup dialog box
works.
Ver. 1.0 Session 5 Slide 24 of 35
25. GUI Applications Development Using .NET Framework
Just a minute
Name the method which is used to show the dialog box?
Answer:
– ShowDialog() method
Ver. 1.0 Session 5 Slide 25 of 35
26. GUI Applications Development Using .NET Framework
PrintPreview Dialog and PrintPreview Control
The PrintPreviewDialog control displays how a document
will look when printed.
It provides the user with the facility to print, zoom, set page
layout options, and to move between pages.
If required PrintPreviewControl control can be used to
create your custom print preview interface.
Let us understand how does the PrintPreview dialog box
works.
Ver. 1.0 Session 5 Slide 26 of 35
27. GUI Applications Development Using .NET Framework
Enabling Security for Printing in Windows Forms
• The .NET Framework uses the PrintingPermission
class to control access to printing capabilities and the
associated PrintingPermissionLevel value to indicate the
level of access.
• The four printing permission levels are:
– AllPrinting Provides full access to all
– DefaultPrinting installed printers.
– SafePrinting
– NoPrinting
Ver. 1.0 Session 5 Slide 27 of 35
28. GUI Applications Development Using .NET Framework
Enabling Security for Printing in Windows Forms (Contd.)
• The .NET Framework uses the PrintingPermission
class to control access to printing capabilities and the
associated PrintingPermissionLevel value to indicate the
level of access.
• The four printing permission levels are:
– AllPrinting
– DefaultPrinting Enables programmatic
– SafePrintng printing to the default printer
– NoPrintng and safer printing through a
restrictive printing dialog
box. DefaultPrinting is a
subset of AllPrinting.
Ver. 1.0 Session 5 Slide 28 of 35
29. GUI Applications Development Using .NET Framework
Enabling Security for Printing in Windows Forms (Contd.)
• The .NET Framework uses the PrintingPermission
class to control access to printing capabilities and the
associated PrintingPermissionLevel value to indicate the
level of access.
• The four printing permission levels are:
– AllPrinting
– DefaultPrinting
– SafePrintng Provides printing only from a
– NoPrintng more-restricted dialog box.
SafePrinting is a subset of
DefaultPrinting.
Ver. 1.0 Session 5 Slide 29 of 35
30. GUI Applications Development Using .NET Framework
Enabling Security for Printing in Windows Forms (Contd.)
• The .NET Framework uses the PrintingPermission
class to control access to printing capabilities and the
associated PrintingPermissionLevel value to indicate the
level of access.
• The four printing permission levels are:
– AllPrinting
– DefaultPrinting
– SafePrintng
– NoPrintng Prevents access to printers.
NoPrinting is a subset of
SafePrinting.
Ver. 1.0 Session 5 Slide 30 of 35
31. GUI Applications Development Using .NET Framework
Just a minute
Identify the property of the PrintPreviewControl, which is
used to get or set the page settings.
1. Document
2. DefaultPageSettings
3. StartPage
4. Zoom
Answer:
2. DefaultPageSettings
Ver. 1.0 Session 5 Slide 31 of 35
32. GUI Applications Development Using .NET Framework
Demo: Creating a Customized PrintPreview Dialog Control
Problem Statement:
Sigma Pvt. Ltd. requires a custom version of the
PrintPreviewDialog control that contains additional options. The
company wants to design a form that contains a
PrintPreviewControl control and an OpenFileDialog control.
The form should enable a user to choose the file to be printed
from the OpenFileDialog and use the properties of the
customized PrintPreviewControl control to print the file.
Provide a solution to the problem.
Ver. 1.0 Session 5 Slide 32 of 35
33. GUI Applications Development Using .NET Framework
Demo: Creating a Customized PrintPreview Dialog Control (Contd.)
Solution:
To meet the preceding requirement, you need to perform the
following tasks:
1. Create a new VC# application.
2. Design the Printing Application form.
3. Add code to perform the desired task.
4. Execute the program and verify the output.
Ver. 1.0 Session 5 Slide 33 of 35
34. GUI Applications Development Using .NET Framework
Summary
In this session, you learned that:
– MDI applications enable you to work with more than one form
within the same application.
– Menus are used to enhance the user interface of an
application.
– Context menus enable users to access the most frequently
used options.
– Toolbar is used to provide easy and quick access to the
frequently used menu items options by using the ToolStrip
control.
– ToolStrip button items can be configured to hold an image by
using the ImageList control.
– The default Print dialog box can be invoked either by adding a
PrintDialog control and a PrintDocument control to the form or
by creating an instance of the PrintDialog and
PrintDocument classes.
Ver. 1.0 Session 5 Slide 34 of 35
35. GUI Applications Development Using .NET Framework
Summary (Contd.)
– The ShowDialog() method is used to display the Print dialog
box on the screen.
– The DialogResult property is used to trap the button that a user
clicks in the Print dialog box
– To invoke the default Windows Page Setup dialog box, either a
PageSetupDialog control is added to the form or an instance of
the PrintSetupDialog class is created.
– The PrintPreviewDialog control displays how a document will
look when printed.
– The PrintPreviewControl can be used to create a custom print
preview interface.
Ver. 1.0 Session 5 Slide 35 of 35
Notas do Editor
Start the session by sharing the session objectives with the students.
Before starting the session, discuss with the students, the importance and advantages of using menus in GUI applications. Collate the answers given by the students and discuss the following points with the students: Menus enable the users to quickly perform an action The users need not to remember the commands To discuss the type of menus, the faculty can actually demonstrate both the types by opening a word application and showing the two types of menus to the students.
Using the same word application, the faculty must demonstrate the concept of MDI form to the students for better understanding.
Using this slide and slide 5,6, and 7, explain to the students that the child forms can be arranged within the parent MDI form in several different ways. The LayoutMdi method is used to arrange the child forms. This method takes different parameters to arrange the child forms.
Using this slide, explain the values of the MdiLayout method for arranging child forms in several ways.
Reiterate the concepts taught earlier by asking the given question.
Reiterate the concepts taught earlier by asking the given question.
Reiterate the concepts taught earlier by asking the given question.
Conduct the activity stated in the slide in a collaborative mode in the class.
Conduct the activity stated in the slide in a collaborative mode in the class.
Using this slide, you can discuss the concept of toolbars available in the GUI applications. An effective way of explaining this would be to demonstrate with the help of small example of toolbar.
Reiterate the concepts taught earlier by asking the given question.
Conduct the activity stated in the slide in a collaborative mode in the class.
Discuss with the students that VC# also provides 3 dialog boxes that can be used for printing of text or graphics. This helps to make applications even more user-friendly. Before discussing the functionality of these dialog boxes, it will be a good practice to demonstrate these dialog boxes using MS-Word application.
The faculty must give a demo of the PrintDialog control. In addition, the faculty must insist that the students should read “ Changing Printer Attached to a User’s Computer” at home.
Reiterate the concepts taught earlier by asking the given question.
The faculty must give a demo of the PageSetupDialog control or PageSetupDialog class.
Reiterate the concepts taught earlier by asking the given question.
The faculty must give a demo of the PrintPreviewDialog control. In additon, discuss all the properties of PrintPreview Control given in the SG
Using slides 23,24,25, and 26 discuss the printing permissions that can be assigned while using the print related dialog boxes.
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 using the summary given in the slides. In addition, you can also ask students summarize what they have learnt in this session.