9.WIndow Form and Controls
9.WIndow Form and Controls
9.WIndow Form and Controls
Chapter (8)
Window Form
1
Contents
What is Window Application?
MessageBox
Layouts
2
What is Window Application?
Windows Forms (WinForms) is a free and open-source graphical (GUI) class library included as a part of Microsoft .
NET providing a platform to write client applications for desktop, laptop, and tablet PCs.
Visual Studio Form along with C# can be used to create a Windows Forms application.
Controls can be added to the Windows forms C# via the Toolbox in Visual Studio.
3
What is Window Form?
Windows Forms is a Graphical User Interface(GUI) class library which is bundled in .Net Framework.
Its main purpose is to provide an easier interface to develop the applications for desktop, tablet, PCs.
The applications which are developed by using Windows Forms or WinForms are known as the Windows
Forms Applications that runs on the desktop computer.
WinForms can be used only to develop the Windows Forms Applications not web applications.
WinForms applications can contain the different type of controls like labels, list boxes, tooltip etc.
4
Categories of Classes in Window Form
Controls
Layout
Components
5
Standard Controls and Components
TextBox TreeView
Label ImageList
Button ListView
CheckBox Panel
ProgressBar MenuStrip
6
DateTimePicker ContextMenuStrip
MessageBox
A predefined window
MessageBox class
C# MessageBox in Windows Forms displays a message with the given text and action buttons.
use MessageBox control to add additional options such as a caption, an icon, or help buttons.
MessageBox.Show(“Good Morning”)
7
MessageBox
represents the buttons to be displayed on a MessageBox and has following values
OK
OKCancel
AbortRetryIgnore
YesNoCancel
YesNo
RetryCancel
8
TextBox
used to display (or) accept as input, a single line of text
In a text box, a user can type data or paste it into the control from the clipboard
Event Description
9
TextBox
Property Description
Text to set the text associated with this control
Width to set width of TextBox
Height to set height of TextBox
BackColor to set the background color of the TextBox
ForeColor to adjust the foreground color of the textbox control
used to add descriptive text to a Form to provide the user with helpful information
Property Description
Text to set the text associated with this Label control
Image to set the image that is displayed on a Label
Event Description
Click Occurs when the control is clicked
11
Button
an interactive component that enables users to communicate with an application
A Button can be clicked by using the mouse, ENTER key, or SPACEBAR if the button has focus
Property Description
Text Gets or sets the text associated with this control
Image Gets or sets the image that is displayed on a button control
BackColor Gets or sets the background color of the control
TextAlign Gets or sets the alignment of the text on the button control
Event Description
Click Occurs when a Button is clicked
12
CheckBox
derived from ButtonBase class
Property Description
Text Gets or sets the text label associated with the CheckBox.
Checked Gets or set a value indicating whether the CheckBox is in the
checked state.
BackColor Gets or sets the background color of the control.
Event Description
CheckedChanged Occurs when the value of the Checked property
changes.
CheckStateChanged Occurs when the value of the Checked property changes
14
RadioButton
derived from ButtonBase class
used as a group
When a user clicks on a radio button, it becomes checked, and all other radio buttons with same group become
unchecked
Use the Checked property to get or set the state of a RadioButton (whether the radio button is selected or not)
If you want the user to choose only one option, radio button is used
When you want the user to choose all appropriate options, check box is used
15
RadioButton
Property Description
Text to set the text associated with this RadioButton contro
Checked Gets or sets a value indicating whether the control is checked.
BackColor Gets or sets the background color of the control.
ForeColor Gets or sets the foreground color of the control.
CheckedAlign determines where the circle is in relation to the label text. It could
be on top of the label, on either side or below
Event Description
16
ListBox
Derived from ListControl class
Enables you to display a list of items to the user that can select these items by clicking
In MultiSimple mode, you can select or deselect any item in a ListBox by clicking it
In MultiExtended mode, you need to hold down the Ctrl key to select additional items or the Shift key to
select a range of items
17
ListBox
Property Description
BackColor Gets or sets the background color for the control
Visible Gets or sets a value indicating whether the control and all its child
controls are displayed
Items Get and set an object representing the collection of the items contained
in this ListBox control
Text Gets or searches for the text of the currently selected item in the
ListBox
Event Description
Click Occurs when the ListBox control is clicked
18
ComboBox
enables the user to select items from the list or enter a new value.
user can type a value in the text field (or) click the button to display a drop down list
19
ComboBox
Property Description
Items Get and set an object representing the collection of the items contained in
this ComboBox control
SelectedItem set currently selected item in the ComboBox
BackColor set the background color for the ComboBox control
ForeColor set the foreground color of the ComboBox control
DropDownStyle specifies whether the list is always displayed or whether the list is
displayed in a drop-down and also specifies whether the text portion can
be edited
Event Description
Click This event occur when the ComboBox control is clicked
SelectedIndexChanged This event occur when the SelectedIndex property has changed
20
CheckedListBox
derived from ListControl class
allows to display a check mark next to the items in the list box
21
CheckedListBox
Property Description
BackColor Gets or sets the background color for the control
ForeColor Gets or sets the foreground color of the control
Items Gets the collection of items in this CheckedListBox
SelectedIndex Gets or sets the zero-based index of the currently selected item in a ListBox
SelectedIndices Gets a collection that contains the zero-based indexes of all currently
selected items in the ListBox
Text Gets or searches for the text of the currently selected item in the ListBox
22
PictureBox
used to display images in bitmap, metafile, icon, JPEG, GIF, or PNG file
set the Image property to the Image you want to display, either at design time or at run time
Normal - Places the upper-left corner of the image at upper left in the picture box
23
PictureBox
Property Description
ImageLocation set the Image you want to display, either at design time or at run
time
24
Timer Control
plays an important role in the development of programs both Client side and Server side development as well as in Windows Services
to increase or decrease the speed in an animation graphics with time schedule etc.
can control programs with Timer Control in millisecond , seconds, minutes and even in hours
Interval property gets or sets the time in milliseconds : one second is equal to 1000 milliseconds
Set the Enabled property to True before running the program, then only the Timer Control starts its function.
Tick event occurs when the specified timer interval has elapsed
25
ProgressBar
indicate the progress of a lengthy operation such as calculating a complex result, copying files or printing
Maximum and Minimum properties define the range of values to represent the progress of a task
26
ProgressBar
Property Description
Minimum Sets the lower value for the range of valid values for progress
Maximum Sets the upper value for the range of valid values for progress
27
DateTimePicker
to display and collect date and time from the user with a specified format
two parts: a label that displays the selected date and
a popup calendar that allows users to select a new date
most important property of the DateTimePicker is the Value property which holds the selected date and time
limit the dates and times that can be selected by setting the MinDate and MaxDate Properties
The values can be displayed in four formats, which are set by the Format property: Long, Short, Time (or) Custom
Event Description
Default Format
ValueChanged Occurs when the Value property changes
28
DateTimePicker
Property Description
Value Gets or sets the date/time value assigned to the control
MaxDate Gets or sets the maximum date and time that can be selected in the control
MinDate Gets or sets the minimum date and time that can be selected in the control
Size used to get or set the height and width of the control
29
TreeView
The TreeView control contains a hierarchy of TreeViewItem controls
The top level in a tree view are root nodes that can be expanded or collapsed if the nodes
have child nodes.
explicitly define the TreeView content or a data source can provide the content.
The user can expand the TreeNode by clicking the plus sign (+) button
navigate through tree views with various properties: FirstNode, LastNode, NextNode,
PrevNode, NextVisibleNode, PrevVisibleNode.
30
ImageList
Gets or sets the ImageList that contains the Image objects used by the tree nodes
The ImageList that contains the Image objects used by the tree nodes.
The default value is a null reference (Nothing in Visual Basic).
31
ListView
an ItemsControl that is derived from ListBox
can use a list view to create a user interface like the right pane of Windows Explorer
The control has four view modes: LargeIcon, SmallIcon, List, and Details
Property Description
Items Gets a collection containing all items in the control
SelectedItems Gets the items that are selected in the control
MultiSelect Gets or sets a value indicating whether multiple items can be
selected.
CheckBoxes Gets or sets a value indicating whether a check box appears
next to each item in the control
Activation Gets or sets the type of action the user must take to activate an
item
32
TabControl and TabPages
TabControl Class
Allow you display multiple dialogs tabs on a single form by switching between the tabs.
TabPage class
A tab page is the actual control that hosts other child controls. represents a tab page.
tabControl1.SelectedIndex = 1;
33
Menus and ToolBars
Windows Forms contains a rich set of classes for creating your own custom toolbars and menus
ToolStrip, MenuStrip, ContextMenuStrip and StatusStrip can be used to create toolbars, menu bars, context
menus, and status bars, respectively.
A Menu on a Windows Form is created with a MainMenu object, which is a collection of MenuItem objects.
MainMenu is the container for the Menu structure of the form and menus are made of MenuItem objects that
represent individual parts of a menu.
You can add menus to Windows Forms at design time by adding the MainMenu component and then appending
menu items to it using the Menu Designer.
34
Common Dialog Boxes
Color Dialog
FontDialog
MessageBox
35
Common Dialog Boxes
ColorDialog Box
a dialog box with a list of colors that are defined for the display system
user can select or create a particular color from the list, which is then reported back to the application when the dialog box
exits
FontDialog Box
a common dialog box displays a list of fonts that are currently installed on the system
user choose attributes for a logical font, such as font family and associated font style, point size, effects
use the Print dialog box to select a printer, configure it, and perform a print job
Print dialog boxes provide an easy way to implement Print and Print Setup dialog boxes in a manner consistent
The Print dialog box includes a Print Range group of radio buttons that indicate whether the user wants to print
The dialog box includes an edit control in which the user can type the number of copies to print.
By default, the Print dialog box initially displays information about the current default printer.
37
Layouts
TableLayoutPanel lets you define cells and rows for laying out controls in a fixed grid
SplitContainer divides your display surface into two or more adjustable parts
38
Thank You
39