Common Properties of Control: Form Controls
Common Properties of Control: Form Controls
Means
Sets/gets the background color of this control.
Sets/gets the background image in the control.
Returns a value specifying if the control can receive the focus.
Returns a value specifying if the control can be selected.
Sets/gets a value specifying if the control has captured the mouse.
Sets/gets a value specifying if the control causes validation for all
Controls that require validation.
Returns a value specifying if the control has the input focus.
Sets/gets the shortcut menu associated with the control.
Sets/gets the cursor displayed when the user moves the mouse pointer
over this control.
Gets the data bindings for the control.
Sets/gets which edge of the parent a control is docked to.
Sets/gets a value specifying if the control is enabled.
Returns a value specifying if the control has input focus.
Sets/gets the current font for the control.
Sets/gets the foreground color of the control.
Returns a value specifying if the control contains child controls.
Sets/gets the height of the control.
Sets/gets the x-coordinate of a controls left edge in pixels.
Sets/gets the coordinates of the upper-left corner of the control with
respect to the upper-left corner of its container.
Sets/gets the controls name.
Sets/gets the controls parent container.
Returns the distance between the right edge of the control and the left
edge of its container.
Sets/gets the height and width of the control.
Sets/gets the tab order of this control in its container.
Sets/gets a value specifying if the user can tab to this control with the
tab key.
Sets/gets an object that contains data about the control.
Sets/gets the text connected to this control.
Sets/gets the top coordinate of the control.
Sets/gets a value specifying if the control is visible.
Sets/gets the width of the control.
Invalidated
KeyDown
KeyPress
KeyUp
Leave
LostFocus
MouseDown
MouseEnter
MouseHover
MouseLeave
MouseMove
MouseUp
RightToLeftChanged
Validated
Validating
Label
Labels usually are used to display text that cannot be edited by the user.
Your code can change the text displayed by a label.
Labels are based directly on the Control class.
Means
Sets/gets a value specifying if the control should be automatically
resized to display all its contents.
Sets/gets the border style for the control.
Sets/gets the flat style appearance of the label control.
Sets/gets the image that is displayed on a Label.
Sets/gets the alignment of an image that is displayed in the control.
Gets the preferred height of the control.
Gets the preferred width of the control.
Sets/gets the alignment of text in the control. This property takes values
BottomCenterVertically aligned at the bottom and horizontally
aligned at the center.
BottomLeftVertically aligned at the bottom, and horizontally
aligned on the left.
BottomRight--Vertically aligned at the bottom, and horizontally
aligned on the right.
MiddleCenter-- Vertically aligned at the middle, and horizontally
UseMnemonic
Example:
Private sub Label1_DoubleClick()
Label1.text=Example of Label1
End Sub
TextBox Control
Every Windows user is familiar with text boxes: theyre exactly what their name
implies: box-like controls in which you can enter text.
Text boxes can be multiline , have scroll bars , be read-only, and have many other
attributes.
The TextBox class is derived from the TextBoxBase class , which is based on
control.
Means
Sets/gets a value specifying if the height of the control automatically
adjusts when the font in the control is changed.
Sets/gets the background color of the control.
Sets/gets the border type of the text box control.
Returns a value specifying if the user can undo the previous operation.
Sets/gets the foreground color.
Sets/gets the maximum number of characters the user can type into the
text box.
Sets/gets a value specifying if this is multiline text box control.
PasswordChar
Means
Appends text to the current text in the text box.
Clears all text from the text box.
Copies the selected text in the text box to the clipboard.
Moves the selected text in the text box to the clipboard.
Replaces the selected text in the text box with the contents of the
clipboard.
Selects text in the text box.
Selects all text in the text box.
Undoes the last edit operation in the text box.
Means
Occurs when the text box is clicked.
Example :
Accessing Text in the Text Box
Private Sub Button1_Click_1()
TextBox1.Text=Hello from Visual Basic
End Sub
KeyPress Event
Private Sub TextBox1_KeyPress()
If (e.KeyChar < 0 or e.KeyChar > 9 ) then
Msgbox(please enter single digits)
e.Handled=true
End if
End Sub
TextChanged Event
Private Sub TextBox1_TextChanged()
TextBox2.Text=sender.Text
End Sub
Private Sub Button1_Click()
Dim TextBox1 as New TextBox()
TextBox1.Size=New Size(150, 20)
TextBox1.Location=New Point(80, 20)
TextBox1.Text=New TextBox
Me.Controls.Add(TextBox1)
End Sub
The windows forms Rich TextBox control is used for displaying, Entering , and
manipulating rich text with formatting.
The Rich TextBox control does everything the TextBox control does , but in
addition , it can display fonts , colors , and links; load text and embedded images
from a file; undo and redo editing operations ; and find specified characters.
Means
Sets/gets a value specifying if the size of the rich text box
automatically adjusts when the font changes.
Sets/gets a value specifying if automatic word selection is enabled.
Sets/gets the border type of the rich text box.
Sets/gets the indentation used in the rich text box when the bullet
style is applied to the text.
Sets/gets the maximum number of characters the user can type into
the rich text box.
Sets/gets a value specifying if this is a multiline RichTextBox
control.
Sets/gets a value specifying if text in the rich text box is read-only.
RightMargin
Means
Appends text to the current text of the rich text box.
Clears all the text from the RichTextBox controls.
Copies the current selection in the rich text box to the clipboard.
Moves the current selection in the rich text box to the clipboard.
Searches for the text within the contents of the rich text box.
Loads the contents of a file into the RichTextBox control.
Pastes the contents of the clipboard into the RichTextBox control.
Saves the contents of the rich text box to a file.
Selects text within the RichTextBox control.
Selects all text in the rich text box.
Undoes the last edit operation in the rich text box.
Event
Click
LinkClicked
Means
Occurs when the rich text box is clicked.
Occurs when the user clicks on a link within the text of the
RichTextBox control.
SelectionChanged Occurs when the selection of text within the RichTextBox control is
changed.
Example:
Accessing text in a Rich Text Box
Private Sub Button1_Click()
RichTextBox2.Text=RichTextBox1.Text
End Sub
Saving and Loading RTF Files from and to rich Text Boxes
Private Sub Button6_Click()
RichTextBox3.SaveFile(text.rtf)
RichTextBox1.LoadFile(text.rtf)
End Sub
Link Labels
Link labels are based on the label class , but also let you support Web-style
hyperlinks to the internet and other Windows forms.
Means
Sets/gets the color for an active link.
Sets/gets the color for a disabled link.
Sets/gets the range in the text to treat as a link.
Sets/gets a value that represents the behavior of a link.
Sets/gets the color for a normal link.
Gets the collection of list in the LinkLabel control.
Sets/gets a value specifying if a link should be displayed as though
it had been visited.
Sets/gets the color used for links that have been visited.
Example :
Private Sub LinkLabel1_LinkClicked ()
LinkLabel1.LinkVisited=true
Dim InfoWindow as New Form2 ()
InfoWindow.Show ()
End Sub
Buttons
There is no more popular control in visual basic then buttons , with the possible
exception of text boxes.
Buttons are the plain controls that you simply click and release, the buttons you
see everywhere in visual basic applications-usually just rounded rectangular, gray
buttons with a caption.
Like other window controls, the button class is based on control class.
In fact, the button class is based directly on the ButtonBase class , which is also
the base class for other types of buttons.
Means
DailogResult Gets/sets the value return to the parent form when the button is clicked.
Often used when youre creating dialog boxes.
FlatStyle
Gets/sets a flat style appearance.
Image
Gets/sets an image displayed in a button.
ImageAlign Gets/sets the alignment of the image in a button.
ImageIndex Gets/sets the image list index value of the index displayed in the button.
ImageList
Gets/sets the ImageList that contains the images displayed in a button.
TextAlign
Gets/sets the alignment of the text in the button.
Checkboxes
Checkboxes are also familiar controls-you click a checkbox to select it , and click
it again to deselect it.
When you select a checkbox a check appears in it, indicating that the box is
indeed selected.
You use a checkbox to give the user an option , such as true/false or yes/no.
Means
Occurs when the appearance property changes.
Occurs when the checked property changes.
Occurs when the CheckState property changes.
Example:
Private Sub CheckBox1_CheckedChanged()
TextBox1.Text=You clicked checkbox1
End Sub
Radio Buttons
Radio buttons, also called option buttons, are similar to checkboxes-the can select
and deselect them-except for two things: they are round where checkboxes are
square, and you usually use radio buttons together in groups.
The functional difference between checkboxes and radio buttons-checkboxes can
work independently, but radio button re intended to work in group.when you select
one radio button in a group, the others are automatically deselected.
Means
Gets/sets the value that determines the appearance of the radio button.
Gets/sets a value indicating whether the checked value and the
appearance of the control automatically change when the radio button is
clicked.
Gets/sets a value indicating whether the radio button is checked.
Gets/sets the flat style appearance of the radio button.
Gets/sets the image that is displayed in a radio button.
Gets/sets the alignment of the image in a radio button.
Gets/sets the image list index value of the image displayed in a radio
button.
Gets/sets the ImageList that contains the image displayed in a radio
button.
Gets/sets the alignment of the text in a radio button.
Means
PerformClick
Generates a click event for the radio button, simulating a click by a user.
List Boxes
As you know, list boxes display a list of items from which the user can select one
or more.
If there are too many items to display at once, a scroll bar automatically appears
to let the user scroll through the list.
In visual basic.NET, each item in a list box is itself an object.
Means
Gets/sets column width; use with multicolumn list boxes.
Indicates which property of objects in a list box to show. If this
property if empty, the objects ToString method is used.
Gets/sets the drawing mode for the list box.
Gets/sets the width a list box can scroll horizontally.
Gets/sets if a horizontal scroll bar is displayed in the list box.
ItemHeight
Items
MultiColumn
ScrollAlwaysVisible
SelectedIndex
SelectedIndices
SelectedItem
SelectedItems
SelectionMode
Sorted
Text
TopIndex
Means
Turns off visual updating of the list box until the EndUpdate method is
called.
ClearSelected
Unselects all the items in a list box.
EndUpdate
Resumes visual updating of the list box.
FindString
Finds the first item in the list box that begins with the indicated string.
FindStringExact Finds the first item in the list box that matches the indicated string
exactly.
GetItemHeight Returns the height of a list box item.
GetSelected
Returns true if the indicated item is selected.
SetSelected
Selects or deselects the indicated item in a list box.
Event of ListBox objects
Event
Means
SelectedIndexChanged Occurs when the selectedIndex property has changed.
Example:
Adding Items to a ListBox
Private Sub Button1_Click()
Dim I As Integer
For i=1 to 20
Windows forms checked list boxes are derived from standard list boxes , except
that they also support a checkbox for each item,
Means
Holds the collection of checked indices in this checked list box.
Holds the collection of checked items in this checked list box.
Gets/sets if the checkbox should be toggled when the
corresponding item is selected.
ColumnWidth
Gets/sets the width of columns; use this only in multicolumn
checked list boxes.
DisplayMember
Indicates which property of objects in the list box to show. If
empty , the checked list box uses the objects ToString method
instead.
HorizontalScrollbar Gets/sets if the checked list box should display a horizontal scroll
bar.
IntegralHeight
Gets/sets a value specifying if the checked list box should
automatically resize so it doesnt partial items,
ItemHeight
Returns the height of an item.
Items
Returns a collection of items in this checked list box.
MultiColumn
Gets/sets if the checked list box allows multiple columns.
ScrollAlwaysVisible Gets/sets if the checked list box always shows a vertical scroll bar.
SelectedIndex
SelectedIndices
SelectedItem
SelectedItems
SelectionMode
Sorted
Text
ThreeDCheckBoxes
TopIndex
Means
Turns off visual updating of the list box EndUpdate method is
called.
ClearSelected
Unselects call items in a checked list box.
EndUpdate
Resumes visual updating of the checked list box.
FindString
Finds the first item that begins with the indicated string in the
checked list box.
FindStringExact
Finds the first item in the checked list box that matches the
indicated string exactly.
GetItemChecked
Gets if the indicated item is checked or not.
GetItemCheckState Gets the check state of the current item.
GetItemHeight
Gets the height of an item in the checked list box.
GetItemText
Gets an items text.
GetSelected
Gets if the indicated item is selected.
IndexFromPoint
Returns the index of the item at indicated coordinates.
SetItemChecked
Checks the item at the indicated index.
SetItemCheckState Sets the indicated items check state.
SetSelected
Selects or clears the selection for the indicated item in a checked
list box.
Event of CheckListBox objects
Event
Means
ItemCheck
Occurs when an items checked state changes.
SelectedIndexChanged Occurs when the Selectedindex property has changed.
Examples:
Combo Boxes
The window forms combo box control is used to display data in a drop-down
combo box.
The combo box is made up of two parts: The top part is a text box that allows the
user to type in all or part of a list item.
The part is a list box that displays a list of items from which the user can select
one or more.
You can allow the user to select an item from the list, or enter their own data.
Means
Indicates which property of the objects in the combo box to show.
If empty, the combo box uses the toString method.
DropDownStyle
Gets/sets the style of the combo box.
DropDown (the default)-Includes a drop-down list and a text box.
The user can select from the list or type in the text box.
Simple-includes a text box and a list, which doesnt dropdown.
The user can select from the list or type in the text box.
DropDownList-this style allows selection only from the dropdown list.
DropDownWidth
Gets/Sets a comboboxs drop-down parts width.
DropDownList
Gets/Sets a combo box drop-down parts width.
DroppedDown
Gets/Sets if the combo box is displaying its drop-down part.
Focused
Gets a value specifying if the combo box has focus.
ItemHeight
Gets the height of an item in a combo box.
Items
Gets a collection of an item in this combo box.
MaxDropDownItems Gets/Sets the maximum number of items visible in the drop-down
part of a combo box.
MaxLength
Gets/Sets the maximum number of characters in the combo boxs
text box.
SelectedIndex
Gets/Sets the index of the currently selected item.
SelectedText
Gets/Sets the selected text in the text box part of a combo box.
SelectionLength
Gets/Sets the number of characters selected in the text box part of
the combo box.
SelectionStart
Gets/Sets the beginning index of selected text in the combo box.
Sorted
Gets/Sets if the items in the combo box are sorted.
Methods of comboBox objects
Method
BeginUpdate
Means
Turns off visual updating of the combo box until the EndUpdate
method is called.
EndUpdate
Resumes visual updating of the combo box.
FindString
Finds the first item in the combo box that begins with the indicated
string.
FindStringExact Finds the items that matches the indicated string exactly.
GetItemText
Gets an items text.
Select
Selects a range of text.
SelectAll
Selects all the text in the text box of the combo box.
Means
Occurs when the drop-down portion of a combo box is shown.
Occurs when the DropDownStyle property has changed.
Occurs when the SelectedIndex property has changed.
Examples:
Adding Items to a Combo Box
Private Sub Button1_Click ()
ComboBox1.Items.Add (Zebra)
ComboBox1.Items.Add (tiger)
ComboBox1.Items.Add (hamster)
ComboBox1.Items.Add (aardvark)
End Sub
TextChanged Events
Private Sub ComboBox1_TextChanged ()
TextBox1.Text=ComboBox1.Text
End Sub
SelectedIndexChanged Events
Private Sub ComboBox1_SelectedIndexChanged ()
TextBox1.Text=Selected item text: & ComboBox1.SelectedItems.ToString () &
Selected Index: & ComboBox1.SelectedItems.ToString ()
End Sub
Removing Items from a Combo Box
Private Sub Button1_Click ()
ComboBox1.Items.RemoveAt (1)
End Sub
Clearing a Combo Box
Private Sub Button1_Click ()
ComboBox1.Items.Clear ()
End Sub
Picture Boxes
Picture boxes are used to display graphics from a bitmap, icon, JPEG, GIF or
other image file type.
The PictureBox class is derived directly from the Control class.
Property
BorderStyle
Image
SizeMode
Means
Gets/sets the border style for the picture box.
Gets/sets the image that is in a picture box.
Picture boxes will resize themselves to fit their contents if you set their
SizeMode property
Normal standard picture box behavior (the upper-left corner of the image
is placed at upper left in the picture box).
StretchImage allows you to stretch the image in code.
AutoSize Fits the picture box to the image.
CenterImage Centers the image in the picture box.
DateTime Picker
You can set a date and time in a date-time picker just by editing the displayed
values in the control; if you click the arrow in the date-time picker, it displays a
month calendar, just as a combo box would display a drop-down list; you can
make selections just by clicking the calendar.
Means
Gets/sets the font style for the calendar.
Gets/sets the foreground color of the calendar.
Gets/sets the background color of the calendar month.
Gets/sets the background color of the calendar title.
Gets/sets the foreground color of the calendar title.
Gets/sets the foreground color of the calendar trailing dates.
Gets/sets whether the value property holds a valid datetime value.
Gets/sets a custom date-time format string.
Gets/sets the alignment of the drop-down calendar on the
date-time control.
Gets/sets the format of dates and times.
You create a custom format string using these items:
d- The one or two digit day.
dd-the two digit day. note that single-digit day values are
preceded by a zero.
ddd-the three-character day-of-week abbreviation.
dddd-the full day-of-week name.
h-the one or two digit hour in 12-hour format.
hh-the two-digit hour in 12-hour format. note that singledigit values are preceded by a zero.
H-the one or two digit hour in 24-hour format.
HH-the two-digit hour in 24-hour format. note that singledigit values are preceded by a zero.
m-the one or two digit minute.
mm-the two-digit minute. note that single-digit values are
preceded by a zero.
M-the one or two digit month number.
MM-the two-digit month number. note that single-digit
values are preceded by a zero.
MMM-the three character month abbreviation.
MMMM-the full month name.
s-the one or two digit seconds.
ss-the two-digit seconds. Note that single-digit values are
preceded by a zero.
t-the one-letter AM/PM abbreviation (AM is displayed as
A).
tt-the two-letter AM/PM abbreviation (AM is displayed
as AM).
y-the one-digit year (2002 is displayed as 2).
yy-the last two digits of the year(2002 is displayed as
MaxDate
MinDate
PreferredHeight
ShowCheckBox
ShowUpDown
Text
Value
02).
yyyy-the full year (2002 is displayed as 2002).
Gets/sets the maximum selectable date and time.
Gets/sets the minimum selectable date and time.
Holds the preferred height of the date-time picker control.
Gets/sets if a check box should appear to the left of a
selected date.
Gets/sets if an up-down control should be used to adjust
date-time values.
Gets/sets the text in this control.
Gets/sets the date-time value.
Means
Occurs when the drop-down calendar disappears.
Occurs when the drop-down calendar appears.
Occurs when the Format property value has changed.
Occurs when the value property changes.
Example:
Handling Date-Time Picker Events
Private Sub DateTimePicker1_ValueChanged ()
TextBox1.Text=Date selected: & DateTimePicker1.Text
End Sub
Setting Date-Time Picker Custom Formats
Private Sub Form1_Load ()
DateTimePicker1.Format= DateTimePickerFormat.Custom
DateTimePicker1.CustomFormat-MMMM dd hh:mm:ss tt
End Sub
Notify Icons
Notify icons let you display an icon in the status notification area of the windows
taskbar (in the indented panel at extreme right in the taskbar) called the windows
system tray.
Events
Click
DoubleClick
Example
Handling Notify Icon Events
Tool Tips
All windows users know what tool tips are- theyre those small windows that
appear with explanatory text when you let the mouse rest on a control or window.
Thats what tool tips are used for to give quick help when the mouse rests on an
item.
Means
Gets/Sets if the tool tip control is active.
Gets/Sets the time (in milliseconds) before the tool tip appears.
Gets/Sets the starting delay for the tool tip.
Gets/Sets whether the tool tip should appear when its parent control is
not active.
Means
Returns the tool tip text.
Set tooltip
Example
Creating Tool Tips
Private sub form1_load ()
Tooltip1.Settooltip (Me, This Is Form.)
Tooltip2.Settooltip (Button1,This Is A Button)
End sub
Tree views
Property
Border Style
Checkboxes
ImageIndex
Means
Gets/Sets the tree views border style
Gets/Sets whether checkboxes should be displayed next to tree
nodes.
Gets/Sets whether a selection should select the whole width of
the tree view.
Gets/Sets whether the selected tree node stays highlighted when
the tree view loses the focus.
Gets/Sets whether a tree node label should change its appearance
when the mouse pointer moves over it.
Gets/Sets the image list index of the current image.
Image List
Indent
ItemHeight
LabelEdit
Nodes
PathSeprator
Scrollbar
FullRowSelect
HideSelection
HotTracking
SelectedImageINdex
SelectedNodes
ShowLines
ShowPlusMinus
Sorted
TopNode
VisibleCount
ShowRootLines
Means
Occurs when a node checkbox is checked.
Occurs when a tree node is collapsed.
Occurs when a tree node is expanded.
Occurs when a tree node label text is edited.
Occurs when a tree node is selected.
Occurs before a node checkbox is checked.
Occurs before a node is collapsed.
Occurs before a node is expanded.
Occurs before a node label text is edited.
Occurs before a node is selected.
Occurs when an item is dragged into the tree view.
Tree views display nodes in a hierarchical structure, and each node in a tree view
is a TreeNode object.
Means
Gets the actual bounds of the tree node.
Gets/Sets whether the tree node is checked.
FirstNode
FullPath
ImageIndex
Index
IsEditing
IsExpanded
IsSelected
IsVisible
LastNode
NextNode
NextVisibleNode
NodeFront
Nodes
Parent
PrevNode
PrevVisibleNode
SelectedImageIndex
Text
TreeView
Means
Starts editing of the nodes label.
Collapses a node.
Ends editing of the nodes label.
Makes sure the node is visible, scrolling the tree view if needed.
Expands a node.
Expands all child nodes.
Gets the number of child nodes.
Removes the current node.
Toggles the tree node between the expanded and collapsed states.
Example
Handling Tree View Events
Private sub TreeView1_afterselect ()
TextBox1.text=you clicked:& e.Node.Text
End Sub
Using Checkboxes in Tree Views
Private Sub Button1_Click ()
TreeView1.Checkbox=True
End Sub
Private Sub TreeView1_AfterCheck ()
If e.Node.Checked Then
TextBox1.Text=you checked: & e.Node.Text
Else
TextBox1.Text=you Unchecked: & e.Node.Text
End if
End Sub
Progress Bars
Progress bars are those simple controls that show the progress of some operation
by displaying rectangles in a horizontal bar.
Means
Gets/Sets the front of the progress bars text.
Gets/Sets the foreground color of the progress bar.
Gets/Sets the progress bars maximum value.
Gets/Sets the progress bars minimum value.
Gets/Sets the value by which the performstep method will increase a
progress bars value.
Gets/Sets the current value of the progress bar.
ProgressBar1.value+=1
If ProgressBar1.Value=ProgressBar1.Maximum Then
Timer1.Enabled=False
End if
End Sub
Masked TextBox
Masked TextBox Control provides mask feature, which allows you to set the
format of the data of TextBox and validation mechanism for user input on form.
For example, if you want a TextBox to accept date in mm/dd/yyyy format, you
can set masking in the MaskedTextBox.
When a MaskedTextBox control is displayed at run time, it represents the mask
as a series of prompt characters and optional literal. Each editable mask position,
representing a required or optional input, is shown with a single prompt character.
Means
Gets or sets a value that determines whether literals and prompt
characters are copied to the clipboard.
Gets or Sets a value indicating whether the prompt characters in
the input mask are hidden when the masked text box loses
focus.
Gets or sets the text insertion mode of the masked text box
control.
Gets or Sets the input mask to use at run time.
Gets a value indicating whether all required inputs have been
entered into the input mask.
Gets a clone of the mask provider associated with this instance
of the masked text box control.
Gets a value indicating whether all required and optional inputs
have been entered into the input mask.
Gets or Sets the text as it is currently displayed to the user.
(Overrides TextBoxBase.Text.)
Gets or Sets how text is aligned in a masked text box control.
Gets or Sets a value that determines whether literals and prompt
characters are included in the formatted string.
Events
Means
MaskChanged
Occurs after the input mask is changed.
MaskInputRejected Occurs when the users input or assigned character does not match
the corresponding format element of the input mask.
Examples
Public Class Form1
Private Sub Form1_Load ()
Here TextBox is masked as number show you can enter number only
MaskedTextBox1.Mask = 00000000000000000
End Sub
Private Sub Button1_click ()
Enter number will show in Label
Label1.text= Enter Number is +MaskedTextBox1.Text
End Sub
End Class
Component
Image Lists
Image lists are components and do not appear at rum time, store images for use by
various controls, including list views, tree views, toolbars, tab controls,
checkboxes, buttons, radio buttons, and labels.
When you associate an image list with a controls ImageList property, you can
specify which image appears in the control with the ImageIndex property.
The images in an image list are indexed- starting at zero- and you can switch the
image displayed in a control at run time by changing the value of the ImageIndex
property.
Means
Gets the color depth for this image list.
Gets the handle for this image list.
Gets an ImageCollection object for this image list.
ImageSize
Gets/Sets the image size for images in the list.
TransparentColor Gets/Sets the transparent color for this list.
Methods of ImageList objects
Method Means
Draw
Draws the given image.
Example
Using Image Lists With Picture Boxes and Other Controls with Image or
BackgroundImage Properties
Private Sub Form1_Load ()
PictureBox1.Image=ImageList1.Images (0)
End Sub
Dim ImageIndex as Integer= 0
Private Sub Button2_Click ()
If ImageIndex<ImageList1.Images.Count- 1 Then
ImageIndex +=1
Else
ImageIndex = 0
End If
PictureBox1.Image = ImageList1.Images (ImageIndex)
End Sub
Private Sub Pane1_Paint ()
ImageList1.Draw (e.Graphics, 0, 0, 0)
End Sub
Timers
Timers are also very useful controls, because they let you create periodic events. Strictly
speaking, timers are no longer controls but components, and they do not appear in a
window at run time.
Properties of Timer objects
property
Means
Enabled
Interval
Means
Occurs when the timer interval has elapsed (and the timer is enabled).
Example
Private Sub Button1_Click ()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick ()
ProgressBar1.Value +=1
If ProgressBar1.Value= ProgressBar1.Maximum Then
Timer1.Enabled= False
End If
End Sub
Error provider
The windows Forms ErrorProvider component allows you to show user in a nonintrusive way that something is wrong.
It is typically used in conjunction with validating user input on a form, or
displaying errors within a dataset.
An error provider is a better alternative then displaying an error message in a
message box, because once a message box is dismissed, the error message is no
longer visible.
The ErrorProvider component displays an error icon() next to the relevant control,
such as a text box; when the user positions the mouse pointer over the error icon,
a ToolTip appears, showing the error message string.
Help Provider
Help Class
The Help class allows us to display HTML help to users.
The Help class provides two methods : ShowHelp and ShowHelpIndex.
ShowHelp is used to display a help file for a particular control and requires that
control to be displayed along with the help file.
The URL you specify for the help file can be in the form of C:\myHelp(local
machine) or Web.Generally, the Help class is used in conjunction with Menus,
Context Menus.
The ShowHelpIndex method is used to display the index of a specified help file.
We call the ShowHelpIndex method just like we call the ShowHelp method.
Example
Private Sub Button1_Click()
Help.ShowHelp(Label1,F:\1.htm)
End Sub
HelpProvider Component
Means
Returns the Help keyword for the specified control.
Returns the current HelpNavigator setting for the specified control.
Returns the contents of the pop-up Help window for the specified control.
Returns a value indicating whether the specified controls Help should be
displayed.
Infrastructure. Removes the Help associated with the specified control.
Specifies the keyword used to retrieve Help when the user invokes Help
for the specified control.
Specifies the Help command to use when retrieving Help from the Help
file for the specified control.
Specifies the Help string associated with the specified control.
Specifies whether Help is displayed for the specified control.
Example
Private Sub frmHelpProvider_Load()
HelpProvider1.SetHelpString(Button2,I am supported by HelpProvider1)
End Sub
Container Control
Panel
You use panels to group other controls, usually to divide a form into regions by
function.
We can use grouping controls such as panels and group controls to make it clear
which controls are associated and it makes it easier to handle groups of controls
at design time too, because when you move a panel, all the controls it contains are
moved as well.
When we add radio buttons to a form, they are automatically coordinated so that
only one radio button can be selected at a time. If the user selects a new radio
button, all the other options buttons are automatically deselected. But there are
times when thats not convenient; for example, we may have two sets of options
buttons: day of the week and day of the month. We want the user to be able to
select one radio button in each list.
Means
Specifies if the panel will display scroll bars if needed.
Gets/sets the size of the auto-scroll margin.
Gets/sets the minimum size of the auto-scroll.
Gets/sets the location of the auto-scroll position.
Gets the dock padding settings for all edges of the panel.
Group Boxes
Like panels, group boxes are used to provide a grouping for other controls.
Group boxes are similar to panels, but, only group boxes display captions with the
Text property and only the panels can have scroll bars.
Group boxes display frames around their contained controls and can display text
in a caption.
After youve created the group boxes, you can drag other controls into them.
Splitters
Means
Gets/sets the splitters border type.
Gets/sets the minimum size of the container that does not display
controls docked to the edge.
Gets/sets the minimum size of the splitters target.
Gets/sets the current position of the splitter.
Means
Occurs when the splitter has moved.
Occurs as the splitter is moving.
Tab Controls
Tab control is one that (like menus, combo boxes, drop-down list boxes, etc.) is
designed to help you conserve space.
Tab controls work much like the tabs in a set of folders in a filing cabinet; you can
click a tab to display a whole new client area, and each such client area can
display other controls.
Using tabs like this allows you to present page after page of controls , all in the
same space.
Tabs like these are becoming increasingly popular in dialog boxes that let the user
select options.
We use tab pages in tab controls.
Tab pages are descended from Panel controls, so, as youd expect, they can
contain other controls.
Means
Gets/sets where the tabs appear (top, left, etc.).
Gets/sets the appearance of tabs in a tab control.
Gets the bounding rectangle of the tab pages.
Gets/sets whether the tabs should change appearance when the mouse
is over them.
Gets/sets the images to show in tabs.
Gets/sets whether the tab control can show more than one row of
tabs.
Gets the number of rows in the tab strip.
SelectedIndex
SelectedTab
ShowToolTips
TabCount
TabPages
Means
Occurs when the SelectedIndex property is changed.
Menu
There are two main classes involved in standard menu handling MainMenu,
which lets you assign objects of this type to a forms Menu class to install the
corresponding menu system, and MenuItem, which is the class that actually
supports the items in a menu system.
Menus are those controls that allow the user to make selections and also hide
away those selections when theyre not needed, saving space in Windows
applications.
Menus are made up of MenuItem objects that represent the individual parts of a
menu - menu items can be a parent menu or a menu item in a menu.
There are all kinds of options here you can add submenus to menus that will pop
up when the user clicks an arrow in a menu item, display check marks, create
menu separators (horizontal bars used in menus to group menu items), assign
shortcut keys(like Ctrl + H) to menu items, even draw the appearance of menu
items.
The simplest way to do so is at design time, because all you have to do is to add a
MainMenu control from the toolbox to a Windows form. When you do so, the
MainMenu control appears in the component tray under the form designer.
Menu Items
Menus like File or Edit and the actual items in such menus are supported with the
MenuItem class.
This class supports the actual controls in your menu system, and their Click event
that you add ccde to in order to make that menu system active.
This class provides properties that enable you to configure the appearance and
functionality of a menu item.
ContextMenu
MdiList
MdiListItem
MenuItems
MergeOrder
MergeType
Mnemonic
OwnerDraw
Parent
RadioCheck
Shortcut
ShowShortcut
Text
Visible
Property
IsParent
MdiListItem
MenuItems
SourceControl
Means
True if this menu contains any menu items. This property is read
only.
Holds the MenuItem that is used to display a list of MDI child forms.
Holds the collection of MenuItem objects associated with the menu.
Holds the control that is displaying the shortcut menu.
Dialogue Boxes
There are a number of built-in dialog boxes in Visual Basic, which is great,
because developing your own file open, file save, and other dialog boxes not only
takes a lot of work, but gives your program a different look from what Windows
users are already used to.
Open File dialogs
Save File dialogs
Font dialogs
Color dialogs
Print Preview dialogs
Page Setup dialogs
Print dialogs
The Open File dialog lets the user select a file to open. In fact, its the same Open
File dialog used by Windows itself.
Open File dialogs are supported with the OpenFileDialog class.
Means
Gets/sets if the dialog box adds an extension to file names if the user
doesnt supply the extension.
Gets/sets if the dialog box displays a warning if the user specifies a
nonexistent file.
Gets/sets whether the dialog box displays a warning if the user gives
a path that does not exist.
Gets/sets the default file extension.
Gets/sets the file name selected in the file dialog box.
Gets the file names of all selected files.
Filter
Gets/sets the current file name filter string, which sets the choices
that appear in the Save as file type or Files of type box.
FilterIndex
Gets/sets the index of the filter selected in the file dialog box.
InitialDirectory
Gets/sets the initial directory used in the file dialog box.
Multiselect
Gets/sets whether the dialog box allows multiple file selections.
ReadOnlyChecked Gets/sets whether the read-only checkbox is checked.
RestoreDirectory
Gets/sets whether the dialog box should restore the original
directory before closing.
ShowHelp
Gets/sets whether the Help button should be displayed.
ShowReadOnly
Gets/sets whether the dialog displays a read-only check box.
Title
Gets/sets the file dialog box title.
ValidateNames
Gets/sets a value specifying if the dialog box accepts only valid (that
is, Win32) file names.
Methods of OpenFileDialog objects
Method
OpenFile
Reset
ShowDialog
Means
Opens the file selected by the user, with read-only permission. The file is
specified by the FileName property.
Resets all options to their default values.
Shows the dialog box.
Example
Creating Open File Dialogs
Private Sub Button1_Click()
If OpenFileDialog1.ShowDialog()<>DialogREsult.Cancel Then
PictureBox1.Image=Image.FromFile(OpenFileDialog1.FileName)
End if
End Sub
AddExtension
CheckFileExists
CheckPathExists
CreatePrompt
DefaultExt
FileName
FileNames
Filter
FilterIndex
InitialDirectory
OverWritePrompt
RestoreDirectory
ShowHelp
Title
ValidateNames
Example
Creating Save File Dialogs
Private Sub Button_Click()
If SaveFileDialog1.ShowDialog<>DialogResult.Cancel Then
MsgBox(You chose & SaveFileDialog1.FileName)
End if
End Sub
Font DialogBox
The FontDialog class displays a dialog box that lets the user select a font
size,face,color and so on.
It returns Font object in the Font property, and a color object in the Color
property.
Font dialogs are supported by the FontDialog class.
Means
Occurs when the user clicks the Apply
button.
Occurs when the user clicks the Help
button.
Example
Creating Font Dialogs
Private Sub Button1_click()
If FontDialog1.ShowDialog<>DialogResult.Cancel Then
RichTextBox1.Font=FontDialog1.Font
RichTextBox1.Forecolor=FontDialog1.Color
End if
End Sub
Color DialogBox
Means
Resets all dialog options to their default
values.
Shows the dual;og.
Means
Occurs when the user click the Help
button.
Example
Creating Color Dialog
Private Sub Button1_Click()
If ColorDialog1.ShowDialog<>DialogResult.Cancel Then
Label1.Text=Heres my nex color!
Label1.Backcolor=ColorDialog1.Color
End If
End Sub
Print DialogBox
Print dialogs let the user print documents, and these dialogs are suppored with the
PrintDialog class.
Means
Gets/sets Whether the Print to file
checkbox is Enables.
Gets/sets Whether the selection radio
button is enabled.
Gets/sets Whether the FromToPage
radio button is enabled.
Gets/sets the PrintDocument used to obtain
Printersettings.
Gets/sets PrinterSettings dialog box to
modify.
Gets/sets Whether the Print to file
checkbox is enabled.
Gets/sets Whether the Help button is
displayed
Gets/sets Whether the Network button is
displayed.
Means
Resets all dialog options.
Shows the Dialog.
Means
Occurs when the user clicks the Help
button.
Example
Printing
Private Sub MenuItem5_Click()
PrintDialog1.Document=PrintDocument1
PrintDialog1.PrinterSettings=PrintDocument1.PrinterSettings
PrintDialog1.AllowSomePages=True
If PrintDialog1.ShowDialog=DialogResult.Ok Then
PrintDocument1.PrinterSettings=PrintDialog1.PrinterSettings
PrintDocument1.Print()
End if
End Sun
You use Print Preview dialogs to let the user see what a document will look like
when its printed.
This dialog is supported with the PrintPreviewDialog class.
This dialog contains button for printing, zooming in, displaying one or multiple
pages, and closing the dialog box.
Means
Gets/sets the button that is automatically
clicked when the user presses the Enter
key.
Gets/sets Whether a control box is
displayed in the caption bar of the form.
Gets/sets the document to preview.
Gets/sets the border style of the form.
Gets/sets Whether a help button should be
displayed in the caption box of the form.
Gets/sets Whether the maximize button is
displayed in the capltion bar of the form.
Gets the maximum size the form can be
resized to.
Gets/sets whether the minimize button is
displayed in the capltion bar of the form.
Gets the PrintPreviewControl contained in
this form.
Gets/Sets the size of the form.
Gets/Sets the size of the form.
Gets/Sets the Starting position of the form
at run time.
Gets/Sets Whether the form should be
displayed as your applications the topmost
form.
Gets the minimum size the form can be
resized to.
Example
Creating Print Preview Dialogs
Private Sub MenuItem3_Click()
PrintPreviewsDialog1.Document=PrintDocumnt1
PrintPreviewDialog1.ShowDialog()
End Sub
Page Setup DialogBox
You also can use Page Setup dialog to specify page details for printing.
You can let users set border and margin adjustments, headers and footers, and
portrait or landscape orientation, and so on.
Page setup dialog are supported by the PageSetupDalog class.
Means
Gets/Sets Whether the margins section of
the dialog box is enabled.
Gets/Sets Whether the oriention section of
the dialog box (landscape or portrait) is
enables.
Gets/Sets Whether the paper ection of the
dialog box (paper size and paper source) is
enabled.
Gets/Sets Whether the Printer button is
enabled.
Gets/Sets the PrintDocument to get page
settings from.
Gets/Sets the minimum margins the user is
allowed to select. Measured in hundredths
of an inch.
Gets/Sets the page settings to modify.
Gets/Sets the printer settings to modify.
Gets/Sets Whether the Help button is
visible.
Gets/Sets Whether the Network button is
visible.
Means
Resets all dialog option.
Show the dialog.
Means
Occurs when the user clicks the Help
button.
Example
Creating Page Setup Dialog
Private Page Setup Dialogs
PageSetupDialog1.Document=PrintDocument1
PageSetupDialog1.PrinterSettings=PrintDocument1.PrinterSettings
PageSetupDialog1.PageSettings=PrintDocument1.defualtPageSettings
If PageSetupDialog1.ShowDialog=DialogResult.Ok Then
PrintDocument1.PrinterSettings=PageSetupDialog1.PrinterSettings
PrintDocument1.DefualtPageSettings=PageSetupDialog1.PageSettings
End If
End Sub