WINDOWSFORMS
WINDOWSFORMS
I. Core Controls
1) Button
2) Label
3) Link Label
4) TextBox
5) PictureBox
6) Panel
7) GroupBox
8) CheckBox
9) RadioButton
10) ListBox
11) ComboBox
12) DomainUpDown
13) NumericUpDown
14) DateTimePicker
15) MonthCalendar
II. Background Process Controls
16) Timer
17) ProgressBar
III. Menu Controls
18) MenuStrip
19) ContextMenuStrip
IV. Dialog Box Controls
20) ColorDialog
21) FontDialog
22) FolderBrowserDialog
23) OpenFileDialog
24) SaveFileDialog
25) PrintDialog
V. Database Controls
26) DataGridView
VI. System Tray Controls
27) NotifyIcon
VII. Other User Friendly Controls
28) TabControl
29) RichTextBox
30) TrackBar
31) TreeView
1) Button
Properties of Button
Property Description
Name Specifies the name of the control.
Text Specifies the displayable text of the control.
BackColor Specifies the background color of the control.
ForeColor Specifies the foreground color of the control.
Font Specifies the font style of the control’s text.
Enabled Enables / Disables the control.
Visible Displays / Hides the control.
Cursor Specifies the mouse pointer style, when it is over on the control.
Size Specifies the Width and Height of the control.
Location Specifies the X and Y co-ordinations of the control’s position on the form.
TextAlign Specifies the position of the text in the control.
Specifies the image that is to be displayed in the control along with the
Image
text.
ImageAlign Specifies the position of the image in the control
TabIndex Specifies the index of the control in the tab order.
ContextMenuStrip Contains the reference of the respective context menu control.
Events of Button
Event Description
Click Executes when the user clicks the control run time.
DoubleClick Executes when the user double-clicks the control at run time.
MouseMove Executes when the mouse pointer is moves across the control.
MouseEnter Executes when the mouse pointer is focused on to the control.
MouseLeave Executes when the mouse pointer is out of the control.
Executes when any key is pressed on the keyboard, while the focus is on
KeyPress
the control.
Enter Executes when the focus is got on to the control.
Leave Executes when the focus is out of the control.
Design
button1:
Text: Red
Name: btnRed
button2:
Text: Green
Name: btnGreen
button3:
Text: Blue
Name: btnBlue
button1:
Text: Normal
Name: btnNormal
button2:
Text: Minimize
Name: btnMinimize
button3:
Text: Maximize
Name: btnMaximize
button4:
Text: Exit
private void btnNormal_Click(object sender, EventArgs e)
Name: btnExit
{
this.WindowState = FormWindowState.Normal;
}
button1:
Design
Text: Show Background Image
Name: btnShowBackgroundImage
button2:
Text: Clear Background Image
Name: btnClearBackgroundImage
Mainly used for presentation purpose, to display a message or description to the user.
API: System.Windows.Forms.Label
Naming Convension: lblxxxxxx
Properties of Label
Property Description
Name Specifies the name of the control.
Text Specifies the displayable text of the control.
BackColor Specifies the background color of the control.
ForeColor Specifies the foreground color of the control.
Font Specifies the font style of the control’s text.
Enabled Enables / Disables the control.
Visible Displays / Hides the control.
Cursor Specifies the mouse pointer style, when it is over on the control.
Size Specifies the Width and Height of the control.
Specifies the X and Y co-ordinations of the control’s position on the
Location
form.
TextAlign Specifies the position of the text in the control.
Specifies the image that is to be displayed in the control along with
Image
the text.
ImageAlign Specifies the position of the image in the control
TabIndex Specifies the index of the control in the tab order.
ContextMenuStrip Contains the reference of the respective context menu control.
Enables / disables automatic sizing of the control, based on the
AutoSize
text.
Events of Label
Event Description
Click Executes when the user clicks the control run time.
DoubleClick Executes when the user double-clicks the control at run time.
MouseMove Executes when the mouse pointer is moves across the control.
MouseEnter Executes when the mouse pointer is focused on to the control.
MouseLeave Executes when the mouse pointer is out of the control.
Executes when any key is pressed on the keyboard, while the focus
KeyPress
is on the control.
Enter Executes when the focus is got on to the control.
Leave Executes when the focus is out of the control.
3) TextBox
Used to take any user input in the application.
API: System.Windows.Forms.TextBox
Naming Convension: txtxxxxxx
Properties of TextBox
Property Description
Name Specifies the name of the control.
Text Specifies the displayable text of the control.
BackColor Specifies the background color of the control.
ForeColor Specifies the foreground color of the control.
Font Specifies the font style of the control’s text.
Enabled Enables / Disables the control.
Visible Displays / Hides the control.
Cursor Specifies the mouse pointer style, when it is over on the control.
Size Specifies the Width and Height of the control.
Specifies the X and Y co-ordinations of the control’s position on the
Location
form.
TextAlign Specifies the position of the text in the control.
Specifies the image that is to be displayed in the control along with
Image
the text.
ImageAlign Specifies the position of the image in the control
TabIndex Specifies the index of the control in the tab order.
ContextMenuStrip Contains the reference of the respective context menu control.
ReadOnly Enables / disables read-only nature of the textbox. In the read only
textbox, the user can not enter any text.
Enables / disables multiple lines in the text box. By default, the text
MultiLine
box will be single-line textbox.
This is used in multi line textboxes, which automatically moves the
WordWrap
cursor to the next line, when the current line exceeds.
Scrollbars Enables / disables scroll bars in the textbox.
PasswordChar Used to specify the password display character. Ex: *
Specifies the maximum no. of characters, that can be entered in
MaxLength
the textbox.
Events of TextBox
Event Description
TextChanged Executes when any character is typed / removed in the textbox.
Click Executes when the user clicks the control run time.
DoubleClick Executes when the user double-clicks the control at run time.
MouseMove Executes when the mouse pointer is moves across the control.
MouseEnter Executes when the mouse pointer is focused on to the control.
MouseLeave Executes when the mouse pointer is out of the button.
Executes when any key is pressed on the keyboard, while the focus
KeyPress
is on the control.
Enter Executes when the focus is got on to the control.
Leave Executes when the focus is out of the control.
Methods of TextBox
Method Description
Clear() Clears all the contents of the textbox and makes it empty.
Focus() Moves the focus to the control.
label1: Design
Application 71: Demo on TextBox Text: Enter your Name:
Name: lblName label1:
Text: Enter your Name:
textBox1:
Name: lblName
Name: txtName
label2: textBox1:
Text: Message Name: txtName
Name: lblMessage
Visible: false label2:
Text: Message
button1:
Name: lblMessage
Name: btnOK
Visible: false
Text: OK
ForeColor: Red
button1:
Name: btnOK
private void btnOK_Click(object sender, EventArgs e)
Text: OK
{
ForeColor: Red
string name = txtName.Text;
string message = "Welcome to " + name;
lblMessage.Text = message;
lblMessage.Visible = true;
}
Design
Application 72: Demo on TextBox
label1:
Text: Enter First Value:
Name: lblFirstValue
textBox1:
Name: txtFirstValue
label2:
Text: Enter Second Value:
Name: lblSecondValue
textBox2:
Name: txtSecondValue
button1:
Name: btnAdd
Text: +
button2:
Name: btnSubtract
private void btnAdd_Click(object sender, EventArgs e) Text: -
{
int a = Convert.ToInt32(txtFirstValue.Text); button3:
int b = Convert.ToInt32(txtSecondValue.Text); Name: btnMultiply
int c = a + b; Text: *
txtResult.Text = Convert.ToString(c);
} button4:
Name: btnDivide
private void btnSubtract_Click(object sender, EventArgs e) Text: /
{
int a = Convert.ToInt32(txtFirstValue.Text); label3:
int b = Convert.ToInt32(txtSecondValue.Text); Text: Result:
int c = a - b; Name: lblResult
txtResult.Text = Convert.ToString(c);
} textBox3:
Name: txtResult
ReadOnly: true
textBox1:
Name: txtSourceText
label2:
Text: Copied Text:
Name: lblDestinationText
textBox2:
Name: txtDestinationText
label2:
Text: From:
Name: lblFrom
textBox1:
Name: txtFrom
label3:
Text: To:
Name: lblTo
textBox2:
Name: txtTo
button1:
Text: GO:
Name: btnGO
4) CheckBox
Used to take the choice from the user. The check box can be checked or un-
checked by the user.
API: System.Windows.Forms.CheckBox
Naming Convension: chkxxxxxx
Properties of CheckBox
Property Description
Name Specifies the name of the control.
Represents the current status of the check box, whether it is
Checked
checked or un-checked.
Text Specifies the displayable text of the control.
BackColor, ForeColor, Font, Enabled, Visible, Cursor, Size, Location, TextAlign, Image, ImageAlign,
TabIndex, ContextMenuStrip
Events of CheckBox
Event Description
CheckedChanged Executes when the user checks / un-checks the checkbox.
Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Methods of CheckBox
Method Description
Focus() Moves the focus to the control.
Design
checkBox1
label1
5) RadioButton
Used to take the choice from the user. We have to implement two or
more radio buttons. At run time, any one of the radio buttons can be
selected.
API: System.Windows.Forms.RadioButton
Naming Convension: rbxxxxxx
Properties of RadioButton
Property Description
Name Specifies the name of the control.
Text Specifies the displayable text of the control.
Represents the current status of the check box, whether it is
Checked
checked or un-checked.
BackColor, ForeColor, Font, Enabled, Visible, Cursor, Size, Location, TextAlign, Image, ImageAlign,
TabIndex, ContextMenuStrip
Events of RadioButton
Event Description
CheckedChanged Executes when the user selects the radio button.
Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Methods of RadioButton
Method Description
Focus() Moves the focus to the control.
radioButton1:
Text: Beige
Name: rbBeige
radioButton2:
Text: Light Green
Name: rbLightGreen
radioButton3:
Text: Light Yellow
Name: rbLightYellow
radioButton4:
Text: Bisque:
Name: rbBisque
API: System.Windows.Forms.LinkLabel
Naming Convension: lnkxxxxxx
Properties of LinkLabel
Property Description
Name Specifies the name of the control.
Text Specifies the displayable text of the control.
LinkColor Specifies the default link color
VisitedLinkColor Specifies the visited link color
ActiveLinkColor Specifies the active link color
BackColor, ForeColor, Font, Enabled, Visible, Cursor, Size, Location, TextAlign, Image, ImageAlign,
TabIndex, ContextMenuStrip
Events of LinkLabel
Event Description
LinkClicked Executes when the user clicks on the link.
Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Methods of LinkLabel
Method Description
Focus() Moves the focus to the control.
7) PictureBox
Used to display an image on the form, at desired place.
API: System.Windows.Forms.PictureBox
Naming Convension: picxxxxxx
Properties of PictureBox
Property Description
Name Specifies the name of the control.
Image Specifies the image, which is to be displayed in the control.
Specifies mode of the image sizing in the control.
SizeMode
(Normal, Stretch, Auto Size, Center, Zoom)
BackColor, Enabled, Visible, Cursor, Size, Location, ContextMenuStrip
Events of PictureBox
Event Description
Click Executes when the user clicks on the picture box.
DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Design
API: System.Windows.Forms.Panel
Naming Convension: pnlxxxxxx
Properties of Panel
Property Description
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, BackgroundImage,
BackgroundImageLayout, ContextMenuStrip, BorderStyle
Events of Panel
Event Description
Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
panel1
button1
button2
Note: When you want to create multiple groups of radio buttons, then use the panel or group box
control to group-up those radio buttons.
9) GroupBox
API: System.Windows.Forms.GroupBox
Naming Convension: grpxxxxxx
Properties of GroupBox
Property Description
Name, Text, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, BackgroundImage,
BackgroundImageLayout, ContextMenuStrip
Events of GroupBox
Event Description
Enter, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Leave
txtMyTextBox
grpBackgroundColor
grpForegroundColor
rbWhite
rbRed
rbYellow
rbBlue
rbGreen
rbOrange
10) ListBox
This contains multiple options (items). Among those items, the user can
select any one option. In some list boxes, multiple items also can be
selected. Those list boxes are called as “Mutiple item selection list
boxes”.
API: System.Windows.Forms.ListBox
Naming Convension: lstxxxxxx
Properties of ListBox
Property Description
Items Contains the list of items, that can be displayed in the list box.
Specifies mode of the item selection.
None – No item can be selected.
SelectionMode One - Single item can only be selected
MultiSimple – Multiple items can be selected, directly by clicking on the items.
MultiExtended – Multiple items can be selected, with Shift+Click or Ctrl+Click.
Sorted Enables / disables automatic sorting of items
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip
Events of ListBox
Event Description
SelectedIndexChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Leave
Methods of ListBox
Property Description
lstObj.Items.Add(“xxxxx”) Adds a new item at the end of the list box items.
lstObj.Items.Insert(index, “xxxx”) Inserts a new item at the specified position.
lstObj.Items.RemoveAt(index) Removes an item, based on its index.
lstObj.Items.Clear() Removes all the items in the list box.
Searches the given string the items collection, and returns the
lstObj.Items.IndexOf(“xxxx”)
index, if it found; otherwise, it returns -1.
Design
lblSelectCourse
lstCourses
lblSelectedCoursePrompt
lblSelectedCourse
lblSelectedCourseIndexPrompt
lblSelectedCourseIndex
Design
grpCities
lstCities
grpOptions
lblNewCity
txtNewCity
btnAdd
btnRemoveCity
brnClearAll
btnShowCount
Design
lblAvailableBooks
lblSelectedBooks
lstAvailableBooks
Sorted: true
SelectionMode: MultiSimple
lstSelectedBooks
Sorted: true
btnSend
11) ComboBox
API: System.Windows.Forms.ComboBox
Naming Convension: cmbxxxxxx
Properties of ComboBox
Property Description
Items Contains the list of items, that can be displayed in the list box.
Simple: It looks like a text box, but the items can be accessed by pressing up / down
arrow keys.
DropDownStyle DropDown: It is the default value. The user can type new text (or) can select the
items from the list.
DropDownList: The user can type new text. Only selection is possible.
Sorted Enables / disables automatic sorting of items
Name, Text, TextAlign, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip
Events of ComboBox
Event Description
SelectedIndexChanged, TextChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave,
KeyPress, Leave
Run Time Properties of Combo Box
Property Description
cmbObj.SelectedItem Represents the currently selected item in the combo box.
Represents the index of the currently selected item in the combo
cmbObj.SelectedIndex
box.
cmbObj.Items.Count Represents the total no. of items in the combo box.
cmbObj.Items[index] Gets the specified item, based on the given index.
cmbObj.Text Gets the text, entered in the combo box.
Methods of ComboBox
Method Description
cmbObj.Items.Add(“xxxxx”) Adds a new item at the end of the combo box items.
cmbObj.Items.Insert(index, “xxxx”) Inserts a new item at the specified position.
cmbObj.Items.RemoveAt(index) Removes an item, based on its index.
cmbObj.Items.Clear() Removes all the items in the combo box.
Searches the given string the items collection, and returns the
cmbObj.Items.IndexOf(“xxxx”)
index, if it found; otherwise, it returns -1.
cmbObj.Clear() Clears the text entered in the combo box.
lblSelectCourse
cmbCourse
Application 84: Demo on ComboBox Items: .NET, Java, C, C++,
Oracle
Design DropDownStyle:
DropDownList
lblFee
txtFee
ReadOnly: true
12) NumericUpDown
This offers to enter a numerical value, within a given range. The user can enter a
value, out of the range.
API: System.Windows.Forms.NumericUpDown
Naming Convension: numxxxxxx
Properties of NumericUpDown
Property Description
Value Gets or sets the current value in the NumericUpDown control.
DecimalPlaces Specifies the no. of decimal places in the value
Minimum Specifies the minimum value in the range.
Maximum Specifies the maximum value in the range.
TextAlign Left / Center / Right
UpDownAlign Left / Right
Name, ReadOnly, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, BackgroundImage,
BackgroundImageLayout, ContextMenuStrip, BorderStyle
Events of NumericUpDown
Event Description
ValueChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
13) DomainUpDown
API: System.Windows.Forms.DomainUpDown
Naming Convension: domxxxxxx
Properties of DomainUpDown
Property
Items, Sorted, Name, Text, TextAlign, BackColor, ForeColor, Font, Enabled, Visible, Size, Location,
ContextMenuStrip
Events of DomainUpDown
Event
SelectedItemChanged, TextChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave,
KeyPress, Leave
Run Time Properties of DomainUpDown
Property
domObj.SelectedItem, domObj.SelectedIndex, domObj.Items.Count, domObj.Items[index], domObj.Text
Methods of DomainUpDown
Method
domObj.Items.Add(“xxxxx”) Adds a new item at the end of the domainupdown items.
domObj.Items.Insert(index, “xxxx”) Inserts a new item at the specified position.
domObj.Items.RemoveAt(index) Removes an item, based on its index.
domObj.Items.Clear() Removes all the items in the domainupdown.
Searches the given string the items collection, and returns the
domObj.Items.IndexOf(“xxxx”)
index, if it found; otherwise, it returns -1.
domObj.Clear() Clears the text entered in the domainupdown.
txtMyText
lblFont
lblSize
domFont
Items: Times New Roman, Tahoma,
Arial, Arial Black, Century Gothic,
Trebuchet MS, Palatino Linotype
Text: Tahoma
Design
14) DateTimePicker
API: System.Windows.Forms.DateTimePicker
Naming Convension: dtPickerxxxxxx
Properties of DateTimePicker
Property Description
Value Gets or sets the current value in the control.
Format Specifies the format of the date selection. (Short / Long / Time / Custom)
Used to specify the customer date formats. (with words and symbols like dd,
CustomFormat
mm, yyyy, -, / etc.)
ShowUpDown Enables / Disables the “up/down” buttons in the control.
MinDate Specifies the minimum date, that can be selected at run time.
MaxDate Specifies the maximum date, that can be selected at run time.
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip
Events of DateTimePicker
Event
ValueChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Design
lblSelectDOB
dtPickerDOB
Format: Short
lblAgePrompt
lblAge
15) MonthCalendar
API: System.Windows.Forms.MonthCalendar
Naming Convension: monCalxxxxxx
Properties of MonthCalendar
Property Description
ShowToday Displays / hides today’s date at the bottom of the control.
ShowWeekNumbers Displays / hides the week no’s at left side.
MinDate Specifies the minimum date, that can be selected at run time.
MaxDate Specifies the maximum date, that can be selected at run time.
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, ContextMenuStrip
Events of MonthCalendar
Event Description
DateChanged, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Note: There is not any property, that gets the currently selected date in the calendar; so that, we
have to use “DateRangeEventArgs” class object to access currently selected date value in the
“DateChanged” event.
Design
lblSelectAnyDate
monCalMyDate
ShowWeekNumbers: true
lblSelectDate
16) TrackBar
API: System.Windows.Forms.TrackBar
Naming Convension: trkxxxxxx
Properties of TrackBar
Property Description
Value Gets or sets the current value in the control.
Minimum Specifies the minimum value in the range.
Maximum Specifies the maximum value in the range.
TickFrequency Specifies the difference between each tick.
Orientation Horizontal / Vertical
TickStyle None, TopLeft, BottomRight, Both
Name, BackColor, ForeColor, Enabled, Visible, Size, Location, ContextMenuStrip, BorderStyle
Events of TrackBar
Event Description
Scroll, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Design
lblFontSize
trkFontSize
Minimum: 1
Maximum: 200
TickFrequency: 5
lblMyText
Text: 10
17) Timer
It is known as “Invisible Control”. That means it can’t be displayed on the form UI.
But it works during the execution time. It performs background processing. It
executes a certain logic, whenever a certain interval time is completed.
API: System.Windows.Forms.Timer
Naming Convension: tmrxxxxxx
Properties of Timer
Property Description
Interval Specifies the interval time of the timer, in the form of mille seconds.
Name, Enabled
Events of Timer
Event
Tick Executes on every completion of interval time.
tmrTime
Interval: 1000
Enabled: true
lblTime
Design
tmrBackColor
Interval: 500
Enabled: true
int n = 0;
18) ProgressBar
It shows the progress of a certain process. It’s value is
limited to the range of 0 to 100. Whenever its value is
reached to 100, that means the process is completed. It can be implemented with the combination of
timer control.
API: System.Windows.Forms.ProgressBar
Naming Convension: prgxxxxxx
Properties of ProgressBar
Property Description
Value Gets or sets the current value in the control.
Minimum Specifies the minimum value in the range.
Maximum Specifies the maximum value in the range.
Name, BackColor, ForeColor, Enabled, Visible, Size, Location, ContextMenuStrip, BackgroundImage,
BackgroundImageLayout
Events of ProgressBar
Event Description
Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
API: System.Windows.Forms.MenuStrip
Naming Convension: mnuxxxxxx
Properties of MenuStrip
Property Description
Dock Top, Bottom, Left, Right, Fill
TextDirection Horizontal, Vertial90, Vertical270.
Name, BackColor, ForeColor, Font, Enabled, Visible, Size, Location, BackgroundImage,
BackgroundImageLayout, ContextMenuStrip
Events of MenuStrip
Event Description
ItemClicked, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
20) ContextMenuStrip
It is also a menu related control, similar to MenuStrip. But the context menu would be displayed,
when the user right clicks on a control or a form, at run time. This is also a collection of menu items.
The context
menu is also called as “Shortcut menu”. The “ContextMenuStrip” is an invisible control.
API: System.Windows.Forms.ContextMenuStrip
Naming Convension: conMnuxxxxxx
Properties of ContextMenuStrip
Property Description
Name, BackColor, Font, Enabled, Size, Location, BackgroundImage, BackgroundImageLayout,
ContextMenuStrip
Events of ContextMenuStrip
Event Description
ItemClicked, Click, DoubleClick, MouseMove, MouseEnter, MouseLeave, KeyPress, Enter, Leave
Design
txtMyText