Ucs15402 VB - Net Unit 2 Notes
Ucs15402 VB - Net Unit 2 Notes
1. Properties
All the Visual Basic Objects can be moved, resized or customized by setting
their properties. A property is a value or characteristic held by a Visual
Basic object, such as Caption or Fore Color.
Where
For example,
Form1.Caption = "Hello"
2. Methods
A method is a procedure created as a member of a class and they cause an
object to do something. Methods are used to access or manipulate the
characteristics of an object or a variable. There are mainly two categories of
methods you will use in your classes −
If none of the existing methods can perform your desired task, you
can add a method to a class.
For example, the MessageBox control has a method named Show, which is
called in the code snippet below −
Handles Button1.Click
MessageBox.Show("Hello, World")
End Sub
End Class
3. Events
An event is a signal that informs an application that something important
has occurred. For example, when a user clicks a control on a form, the form
can raise a Click event and call a procedure that handles the event. There
are various types of events associated with a Form like click, double click,
close, load, resize, etc.
End Sub
Basic Controls
VB.Net provides a huge variety of controls that help you to create rich user
interface. Functionalities of all these controls are defined in the respective
control classes. The control classes are defined in
the System.Windows.Forms namespace.
1. Form
Visual Basic Form is the container for all the controls that make up the user
interface. Every window you see in a running visual basic application is a
form, thus the terms form and window describe the same entity. Visual
Studio creates a default form for you when you create a Windows Forms
Application.
Form Properties
Following table lists down various important properties related to a form.
These properties can be set or read during application execution. You can
refer to Microsoft documentation for a complete list of properties associated
with a Form control −
FixedToolWindow − A fixed
window with a Close button only. It
looks like the toolbar displayed by
the drawing and imaging
applications.
WindowsDefaultBounds − The
form is positioned at the default
location and size determined by
Windows.
WindowsDefaultLocation − The
form is positioned at the Windows
default location and has the
dimensions you've set at design
time.
Form Methods
The following are some of the commonly used methods of the Form class.
You can refer to Microsoft documentation for a complete list of methods
associated with forms control −
1 Activate
2 ActivateMdiChild
3 AddOwnedForm
4 BringToFront
5 CenterToParent
Centers the position of the form within the bounds of the
parent form.
6 CenterToScreen
7 Close
8 Contains
9 Focus
10 Hide
11 Refresh
12 Scale(SizeF)
Scales the control and all child controls by the specified scaling
factor.
13 ScaleControl
14 ScaleCore
15 Select
Activates the control.
16 SendToBack
17 SetAutoScrollMargin
18 SetDesktopBounds
19 SetDesktopLocation
20 SetDisplayRectLocation
21 Show
22 ShowDialog
Form Events
Following table lists down various important events related to a form. You
can refer to Microsoft documentation for a complete list of events
associated with forms control −
2. TextBox Control
Text box controls allow entering text on a form at runtime. By default, it
takes a single line of text, however, you can make it accept multiple texts
and even add scroll bars to it.
Let's create a text box by dragging a Text Box control from the Toolbox and
dropping it on the form.
The Properties of the TextBox Control
The following are some of the commonly used properties of the TextBox
control −
1
AcceptsReturn
2
AutoCompleteCustomSource
3
AutoCompleteMode
Gets or sets an option that controls how automatic completion works for
the TextBox.
4 AutoCompleteSource
Gets or sets a value specifying the source of complete strings used for
automatic completion.
5
CharacterCasing
Gets or sets whether the TextBox control modifies the case of characters
as they are typed.
6
Font
7 FontHeight
8
ForeColor
9 Lines
10
Multiline
11
PasswordChar
12 ReadOnly
Gets or sets a value indicating whether text in the text box is read-only.
13 ScrollBars
None
Horizontal
Vertical
Both
14
TabIndex
Gets or sets the tab order of the control within its container.
15 Text
16 TextAlign
Gets or sets how text is aligned in a TextBox control. This property has
values −
Left
Right
Center
17
TextLength
18
WordWrap
1 AppendText
2
Clear
Clears all text from the text box control.
3
Copy
4
Cut
5 Paste
Replaces the current selection in the text box with the contents of
the Clipboard.
6
Paste(String)
Sets the selected text to the specified text without clearing the undo
buffer.
7 ResetText
8
ToString
9
Undo
1
Click
2 DoubleClick
Occurs when the control is double-clicked.
3
TextAlignChanged
3. Label Control
The Label control represents a standard Windows label. It is generally used
to display some informative text on the GUI which is not changed during
runtime.
Let's create a label by dragging a Label control from the Toolbox and
dropping it on the form.
1
Autosize
2 BorderStyle
3
FlatStyle
4
Font
5 FontHeight
Gets or sets the height of the font of the control.
6
ForeColor
7
PreferredHeight
8 PreferredWidth
9 TabStop
Gets or sets a value indicating whether the user can tab to the Label.
This property is not used by this class.
10 Text
11
TextAlign
1 GetPreferredSize
2
Refresh
Forces the control to invalidate its client area and immediately redraw
itself and any child controls.
3
Select
4
Show
5 ToString
1
AutoSizeChanged
2
Click
3
DoubleClick
4 GotFocus
5 Leave
6 LostFocus
7
TabIndexChanged
9
TextChanged
4. Button Control
The Button control represents a standard Windows button. It is generally
used to generate a Click event by providing a handler for the Click event.
1
AutoSizeMode
Gets or sets the mode by which the Button automatically resizes itself.
2
BackColor
3
BackgroundImage
4 DialogResult
Gets or sets a value that is returned to the parent form when the button
is clicked. This is used while creating dialog boxes.
5
ForeColor
6 Image
7
Location
8 TabIndex
Gets or sets the tab order of the control within its container.
9 Text
1
GetPreferredSize
2
NotifyDefault
Notifies the Button whether it is the default button so that it can adjust
its appearance accordingly.
3
Select
4 ToString
1 Click
2
DoubleClick
3
GotFocus
4 TabIndexChanged
5
TextChanged
5. ListBox Control
The ListBox represents a Windows control to display a list of items to a
user. A user can select an item from the list. It allows the programmer to
add items at design time by using the properties window or at the runtime.
Let's create a list box by dragging a ListBox control from the Toolbox and
dropping it on the form
You can populate the list box items either from the properties window or at
runtime. To add items to a ListBox, select the ListBox control and get to the
properties window, for the properties of this control. Click the ellipses (...)
button next to the Items property. This opens the String Collection Editor
dialog box, where you can enter the values one at a line.
2 BorderStyle
Gets or sets the type of border drawn around the list box.
3 ColumnWidth
4
HorizontalExtent
5 HorizontalScrollBar
6
ItemHeight
7 Items
8 MultiColumn
Gets or sets a value indicating whether the list box supports multiple
columns.
9
ScrollAlwaysVisible
Gets or sets a value indicating whether the vertical scroll bar is shown at
all times.
10 SelectedIndex
Gets or sets the zero-based index of the currently selected item in a list
box.
11
SelectedIndices
12 SelectedItem
13 SelectedItems
Gets a collection containing the currently selected items in the list box.
14
SelectedValue
15 SelectionMode
Gets or sets the method in which items are selected in the list box. This
property has values −
None
One
MultiSimple
MultiExtended
16 Sorted
Gets or sets a value indicating whether the items in the list box are
sorted alphabetically.
17 Text
Gets or searches for the text of the currently selected item in the list
box.
18 TopIndex
Gets or sets the index of the first visible item of a list box.
Methods of the ListBox Control
The following are some of the commonly used methods of the ListBox
control −
1
BeginUpdate
Prevents the control from drawing until the EndUpdate method is called,
while items are added to the ListBox one at a time.
2 ClearSelected
3
EndUpdate
Resumes drawing of a list box after it was turned off by the BeginUpdate
method.
4
FindString
Finds the first item in the ListBox that starts with the string specified as
an argument.
5 FindStringExact
Finds the first item in the ListBox that exactly matches the specified
string.
6 GetSelected
7 SetSelected
8 OnSelectedIndexChanged
8
OnSelectedValueChanged
Raises the SelectedValueChanged event.
1 Click
2 SelectedIndexChanged
6. ComboBox Control
The ComboBox control is used to display a drop-down list of various items.
It is a combination of a text box in which the user enters an item and a
drop-down list from which the user selects an item.
Let's create a combo box by dragging a ComboBox control from the Toolbox
and dropping it on the form.
You can populate the list box items either from the properties window or at
runtime. To add items to a ComboBox, select the ComboBox control and go
to the properties window for the properties of this control. Click the ellipses
(...) button next to the Items property. This opens the String Collection
Editor dialog box, where you can enter the values one at a line.
1 AllowSelection
Gets a value indicating whether the list enables selection of list items.
2 AutoCompleteCustomSource
3 AutoCompleteMode
Gets or sets an option that controls how automatic completion works for
the ComboBox.
4
AutoCompleteSource
Gets or sets a value specifying the source of complete strings used for
automatic completion.
5
DataBindings
6 DataManager
7
DataSource
8 DropDownHeight
9
DropDownStyle
10
DropDownWidth
Gets or sets the width of the of the drop-down portion of a combo box.
11 DroppedDown
Gets or sets a value indicating whether the combo box is displaying its
drop-down portion.
12 FlatStyle
13 ItemHeight
15 MaxDropDownItems
16 MaxLength
Gets or sets the maximum number of characters a user can enter in the
editable area of the combo box.
17
SelectedIndex
18 SelectedItem
19
SelectedText
20 SelectedValue
21 SelectionLength
22
SelectionStart
Gets or sets the starting index of text selected in the combo box.
23 Sorted
Gets or sets a value indicating whether the items in the combo box are
sorted.
24
Text
1 BeginUpdate
Prevents the control from drawing until the EndUpdate method is called,
while items are added to the combo box one at a time.
2
EndUpdate
3 FindString
Finds the first item in the combo box that starts with the string specified
as an argument.
4 FindStringExact
Finds the first item in the combo box that exactly matches the specified
string.
5
SelectAll
Selects all the text in the editable area of the combo box.
1
DropDown
2 DropDownClosed
3 DropDownStyleChanged
4 SelectedIndexChanged
5
SelectionChangeCommitted
Occurs when the selected item has changed and the change appears in
the combo box.
7. RadioButton Control
The RadioButton control is used to provide a set of mutually exclusive
options. The user can select one radio button in a group. If you need to
place more than one group of radio buttons in the same form, you should
place them in different container controls like a GroupBox control.
The Checked property of the radio button is used to set the state of a radio
button. You can display text, image or both on radio button control. You can
also change the appearance of the radio button control by using
the Appearance property.
2
AutoCheck
Gets or sets a value indicating whether the Checked value and the
appearance of the control automatically change when the control is
clicked.
3 CheckAlign
Gets or sets the location of the check box portion of the radio button.
4
Checked
5 Text
6
TabStop
Gets or sets a value indicating whether a user can give focus to the
RadioButton control using the TAB key.
1 PerformClick
2 CheckedChanged
8. CheckBox Control
The CheckBox control allows the user to set true/false or yes/no type
options. The user can select or deselect it. When a check box is selected it
has the value True, and when it is cleared, it holds the value False.
Let's create two check boxes by dragging CheckBox controls from the
Toolbox and dropping on the form.
1
Appearance
2 AutoCheck
3 CheckAlign
Gets or sets the horizontal and vertical alignment of the check mark on
the check box.
4 Checked
5
CheckState
6
Text
7
ThreeState
Gets or sets a value indicating whether or not a check box should allow
three check states rather than two.
1 OnCheckedChanged
Raises the CheckedChanged event.
2
OnCheckStateChanged
3
OnClick
1
AppearanceChanged
Occurs when the value of the Appearance property of the check box is
changed.
2 CheckedChanged
Occurs when the value of the Checked property of the CheckBox control
is changed.
3
CheckStateChanged
9. PictureBox Control
The PictureBox control is used for displaying images on the form. The
Image property of the control allows you to set an image both at design
time or at run time.
Let's create a picture box by dragging a PictureBox control from the Toolbox
and dropping it on the form
Properties of the PictureBox Control
The following are some of the commonly used properties of the PictureBox
control −
1 AllowDrop
Specifies whether the picture box accepts data that a user drags on it.
2 ErrorImage
3 Image
4
ImageLocation
Gets or sets the path or the URL for the image displayed in the control.
5
InitialImage
Gets or sets the image displayed in the control when the main image is
loaded.
6 SizeMode
7
TabIndex
8 TabStop
Specifies whether the user will be able to focus on the picture box by
using the TAB key.
9
Text
10
WaitOnLoad
1
CancelAsync
2 Load
3 LoadAsync
4
ToString
1
CausesValidationChanged
2 Click
3 Enter
4 FontChanged
5 ForeColorChanged
7
KeyPress
8 KeyUp
9
Leave
10 LoadCompleted
11
LoadProgressChanged
12 Resize
13 RightToLeftChanged
14
SizeChanged
15 SizeModeChanged
16 TabIndexChanged
Occurs when the value of the TabIndex property changes.
17
TabStopChanged
18
TextChanged