Chapter 2-Advanced User Interface Enhancement in WinForms
Chapter 2-Advanced User Interface Enhancement in WinForms
https://sites.google.com/a/quest.edu.pk/dr-irfana-memon/lecture-slides
Course Content (1)
Part 1: Console Based Applications
Introduction to Microsoft Visual C# and Visual Studio
Working with variables, Data types, Operators, and Expressions
Visual C# Programming Language Constructs, Creating Methods
Invoking Methods, Handling Exceptions, Creating overloaded Methods
Using Decision Statements
Menues
4
Menus
• Menus are a common Windows tool that make it easy to access
commonly used commands.
• It is not hard to imagine a Windows application with no menu
bar: all of your applications to this point have used buttons.
• Menus are a more natural interface than buttons because they
5
Menus
There are different menus supported in visual studio 2019.
1. ContextMenuStrip
2. MenuStrip
3. StatusStrip
4. ToolStrip
6
ContextMenuStrip
•The ContextMenuStrip control provides functionality of
context menus in Visual Studio 2019.
•To create a ContextMenuStrip control at design-time, you
simply drag and drop a ContextMenuStrip control from Toolbox
onto a Form in Visual Studio.
Figure 1 Figure 2
ContextMenuStrip (Properties)
ContextMenuStrip Items
11
ContextMenuStrip (Properties)
Setting Image a Menu Item Background
•The BackgroundImage property is used to set an image as background of
a menu item.
•The BackgroundImageLayout is used to set the layout of the image.
Menu Grip
•By default, menus do not have a grip but we can show a grip by setting 12
GripStyle property to visible.
ContextMenuStrip (Example)
Contextmenustrip display in the bottom bar of form
This can be used when we click on right of the mouse button
then it will apear a new window, you can add the some option .
For example , Exit, Open dialog box.
20
MenuStrip (Properties)
MenuStrip Items: A Menu control
is nothing without menu items. The
Items property is used to add and
work with items in a MenuStrip.
26
MenuStrip (Example)
After creating all menu items, application form will have view as
shown at Figure
27
Contextmenustrip
vs
MenuStrip
28
StatusStrip
•A typical status bar control, placed on the bottom of a Form is
used to display some text that represents a status of the
application and user actions.
•To build a StatusStrip control at design-time, simply drag and
drop a StatusStrip control from the Toolbox to the Form.
30
StatusStrip (Properties)
• The StatusStrip class is inherited from the
ToolStrip ->ScrollableControl->Control classes
31
StatusStrip (Properties)
Docking a StatusStrip
•A StatusStrip control can be docked at top, bottom, left, right, or
center.
Background Image
The BackColor property sets the background color of a StatusStrip
control. We can also set an image as the background color of a
StatusStrip control.
32
StatusStrip (Properties)
•We can also set the layout of the background image using the
BackgroundImageLayout property that can be stretched, tiled,
centered, centered or zoomed as you can see in Figure.
34
StatusStrip (Properties)
Text Direction
•The TextDirection is another useful property that was missing in the
StatusBar control.
•Using the TextDirection property, we can set the text direction of the
StatusStrip control.
• It has three properties – Horizontal, Vertical90 and Vertical270.
35
StatusStrip (Properties)
Adding StatusStrip Items
•A StatusStrip control is nothing but a container for the child
controls.
•A StatusStrip control can host several child controls. These child
controls are represented by the Items property.
•If you click on the Items property of the StatusStrip control, you will
38
ToolStrip
•Now let's add a few controls to ToolStrip control.
•If you click on a little dropdown handle on a ToolStrip control in
designer, you will see a list of possible controls (See Figure) that can
be added to a ToolStrip.
•To add a control, simply select that control and it will be added to
the ToolStrip control.
40
ToolStripContainer
• A ToolStripContainer has panels on its left, right, top, and
bottom sides for positioning and rafting ToolStrip, MenuStrip,
and StatusStrip controls.
•To create a ToolStrip control at design-time, simply drag and
drop a ToolStrip control from Toolbox onto a Form.
43
Elements of DialogBox
•A dialog box consists of:
Title bar displaying caption and the close icon
Instruction text informing what the user should do (optional)
Content with controls to select or display information
Action area having buttons and link labels
44
Types of DialogBox
• There are two types of dialog boxes namely :
modal dialogbox
modeless dialogbox
• A modal dialog box does not allow the user to activate any
other window in the application unless the dialog box is closed.
• A modeless dialog box allows user to focus and work with the
45
Example of DialogBox
1. Open new project
2. Drag and move two buttons on Form
3. Set properties of these two buttons according your
requirement. We set one button as Modal and other
button as Modaless respectively.
48
Example of DialogBox
7. Run and see by click on Modal and Modaless button.