9.WIndow Form and Controls

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 39

University of Computer Studies

Chapter (8)
Window Form

1
Contents
 What is Window Application?

 What is Window Form?

 Categories of Classes in Window Form

 Standard Controls and Components

 MessageBox

 Standard Controls, its properties and Events

 Menus and ToolBars

 Common Dialog Boxes

 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.

 A Windows form in C# application is one that runs on the desktop of a computer.

 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.

 Controls such as labels, checkboxes, radio buttons, etc.

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

 Control, User Control and Form

 Menus and Toolbars

 Controls

 Layout

 Data and Data Binding

 Components

 Common Dialog Boxes

5
Standard Controls and Components

 TextBox  TreeView

 Label  ImageList

 Button  ListView

 CheckBox  Panel

 RadioButton  FlowLayoutPanel and TableLayoutPanel

 ListBox , ComboBox and CheckListBox  SplitContainer

 Picture Box  TabControl and TabPages

 Timer Control  ToolStrip

 ProgressBar  MenuStrip
6
 DateTimePicker  ContextMenuStrip
MessageBox

 One of the most useful built-in features of windows

 A predefined window

 MessageBox class

 To display a message box, call the static method Show( )

 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

 including multiline editing and password character masking

 In a text box, a user can type data or paste it into the control from the clipboard

 public class TextBox : System.Windows.Forms.TextBoxBase

Event Description

Click Occurs when the text box is clicked

TextChanged Occurs when the Text property value changes

KeyPress Occurs when a character, space or backspace key is


pressed while the control has focus.

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

BorderStyle to adjust the border type of the textbox


MaxLength to set the maximum number of characters the user can
type or paste into the text box control
Multiline to set a value which shows whether this is a multiline
TextBox control
PasswordChar to set the character used to mask characters of a password
in a single-line TextBox control
visible to get or set a value which determine whether the control
and all its child controls are displayed 10
Label
 The Label class is defined in the System.Windows.Forms namespace

 to display text in a set location on the page

 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

 The Button class inherits directly from the ButtonBase class

 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

 allow the user to make multiple selections from a number of options

 to give the user an option, such as true/false (or) yes/no

 can click a check box to select it and click it again to deselect it

 used to accept two-state or three-state response from user

 need to set the checkboxs’ ThreeState property to True

 For Example: checkBox1.ThreeState = true;


 CheckBox’s CheckState property can be:

 Checked – CheckBox is a check mark

 Unchecked – CheckBox does not have a check mark

 Inderterminate- In the state of CheckBox becomes gray 13


CheckBox

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

 enables the user to select a single option from a group of choices

 When a user clicks on a radio button, it becomes checked, and all other radio buttons with same group become
unchecked

 The RadioButton control can display text, an Image, or both

 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

CheckedChanged occurs when the value of the Checked property changes

CheckStateChanged Occurs when the value of the Checked property changes

16
ListBox
 Derived from ListControl class

 Enables you to display a list of items to the user that can select these items by clicking

 Adding and selecting data to the list

 Best choice for Multiple selections (ListBox)

 Data must be added to a list box before it can be useful

 ListBox class has SelectionMode: None, One, MultiSimple, MultiExtended

 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

 derived from ListControl class

 combination of a drop-down list or list box and a single-line editable textbox

 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

 Best choice for only single item selection (ComboBox)

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

 gives all the capability of a list box

 best choice for Multiple selections (CheckedListBox)

 allows to display a check mark next to the items in the list box

 user can place a check mark by one or more items and

 the checked items can be navigated with the CheckedListBox.CheckedItemCollection and


CheckedListBox.CheckedIndexCollection

 By default Checkedlistbox items are unchecked

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

SelectedItem Gets or sets the currently selected item in the ListBox


SelectedItems Gets a collection containing the 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

 change the image displayed in a picture box

 not a selectable control

 There are five different PictureBoxSizeMode is available to PictureBox control.

 AutoSize - Sizes the picture box to the image.

 CenterImage - Centers the image in the picture box.

 Normal - Places the upper-left corner of the image at upper left in the picture box

 StretchImage - Allows you to stretch the image in code

23
PictureBox

Property Description

Image Gets or sets the image that is displayed by PictureBox.

ImageLocation set the Image you want to display, either at design time or at run
time

SizeMode Specifies how an image is positioned within a PictureBox

BorderStyle Indicates the border style for the control

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

 use Timer Object

to set an interval between events, periodic checking,

to start a process at a fixed time schedule,

to increase or decrease the speed in an animation graphics with time schedule etc.

 have no a visual representation and works as a component in the background

 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

 By default the Enabled property of Timer Control is False

 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

documents, downloading a large file from the Web etc.

 used whenever an operation takes more than a short period of time

 Maximum and Minimum properties define the range of values to represent the progress of a task

 by default, Minimum and Maximum are set to 0 and 100

 can only be oriented horizontally

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

Value obtains or sets the current level of 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

 Value property contains the current date and time

 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

 to display information in a hierarchical structure by using collapsible nodes

 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

 expand the TreeNode by calling the TreeNode.Expand method

 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

 displays a list of items with icons

 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

 A TabControl is a collection of tab pages

 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.

 A tab acts as another Form that can host other controls

 Add tab page with TabePages property

tabControl1.SelectedTab = tabControl1.TabPages[3]; (or)

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

 OpenFileDialog and SaveFileDialog

 FontDialog

 PageSetupDialog, PrintPreviewDialog, and PrintDialog

 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

 a color dialog box can be invited by calling ShowDialog() method

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

OpenFileDialog and SaveFileDialog Boxes


 allow users to browse the folders of their computer or any computer on the network and select one or more files to open or
save
36
PrintDialog Box

 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

with Windows standards

 The Print dialog box includes a Print Range group of radio buttons that indicate whether the user wants to print

all pages , a range of pages, or only the selected text

 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

 Panel : a control contains other controls

 By grouping controls together and placing them in a panel

 Is derived from ScrollableControl

 Is base class for FlowLayoutPanel, TableLayoutPanel, TabPage and SplitterPanel

 FlowLayoutPanel lays out all the controls it contains in a serial manner

 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy