0% found this document useful (0 votes)
31 views40 pages

Ucs15402 VB - Net Unit 2 Notes

Uploaded by

Nitesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views40 pages

Ucs15402 VB - Net Unit 2 Notes

Uploaded by

Nitesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

VB.

Net - Basic Controls


An object is a type of user interface element you create on a Visual Basic
form by using a toolbox control. In fact, in Visual Basic, the form itself is an
object. Every Visual Basic control consists of three important elements −

 Properties which describe the object,

 Methods cause an object to do something and

 Events are what happens when an object does something.

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.

Properties can be set at design time by using the Properties window or at


run time by using statements in the program code.

Object. Property = Value

Where

 Object is the name of the object you're customizing.

 Property is the characteristic you want to change.

 Value is the new property setting.

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 you are using a control such as one of those provided by the


Toolbox, you can call any of its public methods. The requirements of
such a method depend on the class being used.

 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 −

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs)

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.

Following is the default structure of a form Load event handler subroutine.


You can see this code by double clicking the code which will give you a
complete list of the all events associated with Form control −

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles


MyBase.Load

'event handler code goes here

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.

The following table lists some of the commonly used controls –

1. Form

Let's start with creating a Window Forms Application by following the


following steps in Microsoft Visual Studio - File → New Project →
Windows Forms Applications
Finally, select OK, Microsoft Visual Studio creates your project and displays
following window Form with a name Form1.

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 −

S.N Properties Description

1 AcceptButton The button that's automatically activated


when you press Enter, no matter which
control has the focus at the time. Usually
the OK button on a form is set as
AcceptButton for a form.

2 CancelButton The button that's automatically activated


when you hit the Esc key.

Usually, the Cancel button on a form is set


as CancelButton for a form.

3 AutoScale This Boolean property determines whether


the controls you place on the form are
automatically scaled to the height of the
current font. The default value of this
property is True. This is a property of the
form, but it affects the controls on the
form.

4 AutoScroll This Boolean property indicates whether


scroll bars will be automatically attached
to the form if it is resized to a point that
not all its controls are visible.

5 AutoScrollMinSize This property lets you specify the


minimum size of the form, before the
scroll bars are attached.

6 AutoScrollPosition The AutoScrollPosition is the number of


pixels by which the two scroll bars were
displaced from their initial locations.

7 BackColor Sets the form background color.

8 BorderStyle The BorderStyle property determines the


style of the form's border and the
appearance of the form −

 None − Borderless window that


can't be resized.

 Sizable − This is default value and


will be used for resizable window
that's used for displaying regular
forms.

 Fixed3D − Window with a visible


border, "raised" relative to the main
area. In this case, windows can't be
resized.

 FixedDialog − A fixed window, used


to create dialog boxes.

 FixedSingle − A fixed window with


a single line border.

 FixedToolWindow − A fixed
window with a Close button only. It
looks like the toolbar displayed by
the drawing and imaging
applications.

 SizableToolWindow − Same as the


FixedToolWindow but resizable. In
addition, its caption font is smaller
than the usual.

9 ControlBox By default, this property is True and you


can set it to False to hide the icon and
disable the Control menu.

10 Enabled If True, allows the form to respond to


mouse and keyboard events; if False,
disables form.

11 Font This property specify font type, style, size

12 HelpButton Determines whether a Help button should


be displayed in the caption box of the
form.

13 Height This is the height of the Form in pixels.


14 MinimizeBox By default, this property is True and you
can set it to False to hide the Minimize
button on the title bar.

15 MaximizeBox By default, this property is True and you


can set it to False to hide the Maximize
button on the title bar.

16 MinimumSize This specifies the minimum height and


width of the window you can minimize.

17 MaximumSize This specifies the maximum height and


width of the window you maximize.

18 Name This is the actual name of the form.

19 StartPosition This property determines the initial


position of the form when it's first
displayed. It will have any of the following
values −

 CenterParent − The form is


centered in the area of its parent
form.

 CenterScreen − The form is


centered on the monitor.

 Manual − The location and size of


the form will determine its starting
position.

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

20 Text The text, which will appear at the title bar


of the form.

21 Top, Left These two properties set or return the


coordinates of the form's top-left corner in
pixels.

22 TopMost This property is a True/False value that


lets you specify whether the form will
remain on top of all other forms in your
application. Its default property is False.

23 Width This is the width of the form in pixel.

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 −

Sr.No. Method Name & Description

1 Activate

Activates the form and gives it focus.

2 ActivateMdiChild

Activates the MDI child of a form.

3 AddOwnedForm

Adds an owned form to this form.

4 BringToFront

Brings the control to the front of the z-order.

5 CenterToParent
Centers the position of the form within the bounds of the
parent form.

6 CenterToScreen

Centers the form on the current screen.

7 Close

Closes the form.

8 Contains

Retrieves a value indicating whether the specified control is a


child of the control.

9 Focus

Sets input focus to the control.

10 Hide

Conceals the control from the user.

11 Refresh

Forces the control to invalidate its client area and immediately


redraw itself and any child controls.

12 Scale(SizeF)

Scales the control and all child controls by the specified scaling
factor.

13 ScaleControl

Scales the location, size, padding, and margin of a control.

14 ScaleCore

Performs scaling of the form.

15 Select
Activates the control.

16 SendToBack

Sends the control to the back of the z-order.

17 SetAutoScrollMargin

Sets the size of the auto-scroll margins.

18 SetDesktopBounds

Sets the bounds of the form in desktop coordinates.

19 SetDesktopLocation

Sets the location of the form in desktop coordinates.

20 SetDisplayRectLocation

Positions the display window to the specified value.

21 Show

Displays the control to the user.

22 ShowDialog

Shows the form as a modal dialog box.

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 −

Sr.No. Event Description

1 Activated Occurs when the form is activated in


code or by the user.

2 Click Occurs when the form is clicked.


3 Closed Occurs before the form is closed.

4 Closing Occurs when the form is closing.

5 DoubleClick Occurs when the form control is


double-clicked.

6 DragDrop Occurs when a drag-and-drop


operation is completed.

7 Enter Occurs when the form is entered.

8 GotFocus Occurs when the form control receives


focus.

9 HelpButtonClicked Occurs when the Help button is


clicked.

10 KeyDown Occurs when a key is pressed while the


form has focus.

11 KeyPress Occurs when a key is pressed while the


form has focus.

12 KeyUp Occurs when a key is released while


the form has focus.

13 Load Occurs before a form is displayed for


the first time.

14 LostFocus Occurs when the form loses focus.

15 MouseDown Occurs when the mouse pointer is over


the form and a mouse button is
pressed.

16 MouseEnter Occurs when the mouse pointer enters


the form.

17 MouseHover Occurs when the mouse pointer rests


on the form.

18 MouseLeave Occurs when the mouse pointer leaves


the form.

19 MouseMove Occurs when the mouse pointer is


moved over the form.

20 MouseUp Occurs when the mouse pointer is over


the form and a mouse button is
released.

21 MouseWheel Occurs when the mouse wheel moves


while the control has focus.

22 Move Occurs when the form is moved.

23 Resize Occurs when the control is resized.

24 Scroll Occurs when the user or code scrolls


through the client area.

25 Shown Occurs whenever the form is first


displayed.

26 VisibleChanged Occurs when the Visible property value


changes.

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 −

Sr.No. Property & Description

1
AcceptsReturn

Gets or sets a value indicating whether pressing ENTER in a multiline


TextBox control creates a new line of text in the control or activates the
default button for the form.

2
AutoCompleteCustomSource

Gets or sets a custom System.Collections.Specialized.StringCollection to


use when the AutoCompleteSourceproperty is set to CustomSource.

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

Gets or sets the font of the text displayed by the control.

7 FontHeight

Gets or sets the height of the font of the control.

8
ForeColor

Gets or sets the foreground color of the control.

9 Lines

Gets or sets the lines of text in a text box control.

10
Multiline

Gets or sets a value indicating whether this is a multiline TextBox


control.

11
PasswordChar

Gets or sets the character used to mask characters of a password in a


single-line TextBox control.

12 ReadOnly

Gets or sets a value indicating whether text in the text box is read-only.

13 ScrollBars

Gets or sets which scroll bars should appear in a multiline TextBox


control. This property has values −

 None
 Horizontal

 Vertical

 Both

14
TabIndex

Gets or sets the tab order of the control within its container.

15 Text

Gets or sets the current text in the TextBox.

16 TextAlign

Gets or sets how text is aligned in a TextBox control. This property has
values −

 Left

 Right

 Center

17
TextLength

Gets the length of text in the control.

18
WordWrap

Indicates whether a multiline text box control automatically wraps words


to the beginning of the next line when necessary.

The Methods of the TextBox Control


The following are some of the commonly used methods of the TextBox
control −

Sr.No. Method Name & Description

1 AppendText

Appends text to the current text of a text box.

2
Clear
Clears all text from the text box control.

3
Copy

Copies the current selection in the text box to the Clipboard.

4
Cut

Moves the current selection in the text box to the Clipboard.

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

Resets the Text property to its default value.

8
ToString

Returns a string that represents the TextBoxBase control.

9
Undo

Undoes the last edit operation in the text box.

Events of the TextBox Control


The following are some of the commonly used events of the Text control −

Sr.No. Event & Description

1
Click

Occurs when the control is clicked.

2 DoubleClick
Occurs when the control is double-clicked.

3
TextAlignChanged

Occurs when the TextAlign property value changes.

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.

Properties of the Label Control


The following are some of the commonly used properties of the Label
control −

Sr.No. Property & Description

1
Autosize

Gets or sets a value specifying if the control should be automatically


resized to display all its contents.

2 BorderStyle

Gets or sets the border style for the control.

3
FlatStyle

Gets or sets the flat style appearance of the Label control

4
Font

Gets or sets the font of the text displayed by the control.

5 FontHeight
Gets or sets the height of the font of the control.

6
ForeColor

Gets or sets the foreground color of the control.

7
PreferredHeight

Gets the preferred height of the control.

8 PreferredWidth

Gets the preferred width of the control.

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

Gets or sets the text associated with this control.

11
TextAlign

Gets or sets the alignment of text in the label.

Methods of the Label Control


The following are some of the commonly used methods of the Label control.

Sr.No. Method Name & Description

1 GetPreferredSize

Retrieves the size of a rectangular area into which a control can be


fitted.

2
Refresh

Forces the control to invalidate its client area and immediately redraw
itself and any child controls.
3
Select

Activates the control.

4
Show

Displays the control to the user.

5 ToString

Returns a String that contains the name of the control.

Events of the Label Control


The following are some of the commonly used events of the Label control −

Sr.No. Event & Description

1
AutoSizeChanged

Occurs when the value of the AutoSize property changes.

2
Click

Occurs when the control is clicked.

3
DoubleClick

Occurs when the control is double-clicked.

4 GotFocus

Occurs when the control receives focus.

5 Leave

Occurs when the input focus leaves the control.

6 LostFocus

Occurs when the control loses focus.

7
TabIndexChanged

Occurs when the TabIndex property value changes.


8
TabStopChanged

Occurs when the TabStop property changes.

9
TextChanged

Occurs when the Text property value changes.

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.

Let's create a label by dragging a Button control from the Toolbox ad


dropping it on the form.

Properties of the Button Control


The following are some of the commonly used properties of the Button
control −

Sr.No. Property & Description

1
AutoSizeMode

Gets or sets the mode by which the Button automatically resizes itself.
2
BackColor

Gets or sets the background color of the control.

3
BackgroundImage

Gets or sets the background image displayed in the control.

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

Gets or sets the foreground color of the control.

6 Image

Gets or sets the image that is displayed on a button control.

7
Location

Gets or sets the coordinates of the upper-left corner of the control


relative to the upper-left corner of its container.

8 TabIndex

Gets or sets the tab order of the control within its container.

9 Text

Gets or sets the text associated with this control.

Methods of the Button Control


The following are some of the commonly used methods of the Button
control −

Sr.No. Method Name & Description

1
GetPreferredSize

Retrieves the size of a rectangular area into which a control can be


fitted.

2
NotifyDefault

Notifies the Button whether it is the default button so that it can adjust
its appearance accordingly.

3
Select

Activates the control.

4 ToString

Returns a String containing the name of the Component, if any. This


method should not be overridden.

Events of the Button Control


The following are some of the commonly used events of the Button control

Sr.No. Event & Description

1 Click

Occurs when the control is clicked.

2
DoubleClick

Occurs when the user double-clicks the Button control.

3
GotFocus

Occurs when the control receives focus.

4 TabIndexChanged

Occurs when the TabIndex property value changes.

5
TextChanged

Occurs when the Text property value changes.


6
Validated

Occurs when the control is finished validating.

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.

Properties of the ListBox Control


The following are some of the commonly used properties of the ListBox
control −

Sr.No. Property & Description


1
AllowSelection

Gets a value indicating whether the ListBox currently enables selection


of list items.

2 BorderStyle

Gets or sets the type of border drawn around the list box.

3 ColumnWidth

Gets of sets the width of columns in a multicolumn list box.

4
HorizontalExtent

Gets or sets the horizontal scrolling area of a list box.

5 HorizontalScrollBar

Gets or sets the value indicating whether a horizontal scrollbar is


displayed in the list box.

6
ItemHeight

Gets or sets the height of an item in the list box.

7 Items

Gets the items of the list box.

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

Gets a collection that contains the zero-based indexes of all currently


selected items in the list box.

12 SelectedItem

Gets or sets the currently selected item in the list box.

13 SelectedItems

Gets a collection containing the currently selected items in the list box.

14
SelectedValue

Gets or sets the value of the member property specified by the


ValueMember property.

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 −

Sr.No. Method Name & Description

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

Unselects all items in the ListBox.

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

Returns a value indicating whether the specified item is selected.

7 SetSelected

Selects or clears the selection for the specified item in a ListBox.

8 OnSelectedIndexChanged

Raises the SelectedIndexChanged event.

8
OnSelectedValueChanged
Raises the SelectedValueChanged event.

Events of the ListBox Control


The following are some of the commonly used events of the ListBox control

Sr.No. Event & Description

1 Click

Occurs when a list box is selected.

2 SelectedIndexChanged

Occurs when the SelectedIndex property of a list box is changed.

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.

Properties of the ComboBox Control


The following are some of the commonly used properties of the ComboBox
control −

Sr.No. Property & Description

1 AllowSelection

Gets a value indicating whether the list enables selection of list items.

2 AutoCompleteCustomSource

Gets or sets a custom System.Collections .Specialized.StringCollection to


use when the AutoCompleteSourceproperty is set to CustomSource.

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

Gets the data bindings for the control.

6 DataManager

Gets the CurrencyManager associated with this control.

7
DataSource

Gets or sets the data source for this ComboBox.

8 DropDownHeight

Gets or sets the height in pixels of the drop-down portion of the


ComboBox.

9
DropDownStyle

Gets or sets a value specifying the style of the combo box.

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

Gets or sets the appearance of the ComboBox.

13 ItemHeight

Gets or sets the height of an item in the combo box.


14
Items

Gets an object representing the collection of the items contained in this


ComboBox.

15 MaxDropDownItems

Gets or sets the maximum number of items to be displayed in the drop-


down part of the combo box.

16 MaxLength

Gets or sets the maximum number of characters a user can enter in the
editable area of the combo box.

17
SelectedIndex

Gets or sets the index specifying the currently selected item.

18 SelectedItem

Gets or sets currently selected item in the ComboBox.

19
SelectedText

Gets or sets the text that is selected in the editable portion of a


ComboBox.

20 SelectedValue

Gets or sets the value of the member property specified by the


ValueMember property.

21 SelectionLength

Gets or sets the number of characters selected in the editable portion of


the combo box.

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

Gets or sets the text associated with this control.

Methods of the ComboBox Control


The following are some of the commonly used methods of the ComboBox
control −

Sr.No. Method Name & Description

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

Resumes drawing of a combo box, after it was turned off by the


BeginUpdate method.

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.

Events of the ComboBox Control


The following are some of the commonly used events of the ComboBox
control −
Sr.No. Event & Description

1
DropDown

Occurs when the drop-down portion of a combo box is displayed.

2 DropDownClosed

Occurs when the drop-down portion of a combo box is no longer visible.

3 DropDownStyleChanged

Occurs when the DropDownStyle property of the ComboBox has


changed.

4 SelectedIndexChanged

Occurs when the SelectedIndex property of a ComboBox control has


changed.

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.

Properties of the RadioButton Control


The following are some of the commonly used properties of the RadioButton
control −

Sr.No. Property & Description


1
Appearance

Gets or sets a value determining the appearance of the radio button.

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

Gets or sets a value indicating whether the control is checked.

5 Text

Gets or sets the caption for a radio button.

6
TabStop

Gets or sets a value indicating whether a user can give focus to the
RadioButton control using the TAB key.

Methods of the RadioButton Control


The following are some of the commonly used methods of the RadioButton
control −

Sr.No. Method Name & Description

1 PerformClick

Generates a Click event for the control, simulating a click by a user.

Events of the RadioButton Control


The following are some of the commonly used events of the RadioButton
control −

Sr.No Event & Description


1
AppearanceChanged

Occurs when the value of the Appearance property of the RadioButton


control is changed.

2 CheckedChanged

Occurs when the value of the Checked property of the RadioButton


control is changed.

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.

The CheckBox control has three


states, checked, unchecked and indeterminate. In the indeterminate
state, the check box is grayed out. To enable the indeterminate state,
the ThreeState property of the check box is set to be True.

Properties of the CheckBox Control


The following are some of the commonly used properties of the CheckBox
control −
Sr.No. Property & Description

1
Appearance

Gets or sets a value determining the appearance of the check box.

2 AutoCheck

Gets or sets a value indicating whether the Checked or CheckedState


value and the appearance of the control automatically change when the
check box is selected.

3 CheckAlign

Gets or sets the horizontal and vertical alignment of the check mark on
the check box.

4 Checked

Gets or sets a value indicating whether the check box is selected.

5
CheckState

Gets or sets the state of a check box.

6
Text

Gets or sets the caption of a check box.

7
ThreeState

Gets or sets a value indicating whether or not a check box should allow
three check states rather than two.

Methods of the CheckBox Control


The following are some of the commonly used methods of the CheckBox
control −

Sr.No. Method Name & Description

1 OnCheckedChanged
Raises the CheckedChanged event.

2
OnCheckStateChanged

Raises the CheckStateChanged event.

3
OnClick

Raises the OnClick event.

Events of the CheckBox Control


The following are some of the commonly used events of the CheckBox
control −

Sr.No. Event & Description

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

Occurs when the value of the CheckState property of the CheckBox


control is changed.

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 −

Sr.No. Property & Description

1 AllowDrop

Specifies whether the picture box accepts data that a user drags on it.

2 ErrorImage

Gets or specifies an image to be displayed when an error occurs during


the image-loading process or if the image load is cancelled.

3 Image

Gets or sets the image that is displayed in the control.

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

Determines the size of the image to be displayed in the control. This


property takes its value from the PictureBoxSizeMode enumeration,
which has values −

 Normal − the upper left corner of the image is placed at upper


left part of the picture box

 StrechImage − allows stretching of the image

 AutoSize − allows resizing the picture box to the size of the


image

 CenterImage − allows centering the image in the picture box

 Zoom − allows increasing or decreasing the image size to


maintain the size ratio.

7
TabIndex

Gets or sets the tab index value.

8 TabStop

Specifies whether the user will be able to focus on the picture box by
using the TAB key.

9
Text

Gets or sets the text for the picture box.

10
WaitOnLoad

Specifies whether or not an image is loaded synchronously.

Methods of the PictureBox Control


The following are some of the commonly used methods of the PictureBox
control −
Sr.No. Method Name & Description

1
CancelAsync

Cancels an asynchronous image load.

2 Load

Displays an image in the picture box

3 LoadAsync

Loads image asynchronously.

4
ToString

Returns the string that represents the current picture box.

Events of the PictureBox Control


The following are some of the commonly used events of the PictureBox
control −

Sr.No. Event & Description

1
CausesValidationChanged

Overrides the Control.CausesValidationChanged property.

2 Click

Occurs when the control is clicked.

3 Enter

Overrides the Control.Enter property.

4 FontChanged

Occurs when the value of the Font property changes.

5 ForeColorChanged

Occurs when the value of the ForeColor property changes.


6
KeyDown

Occurs when a key is pressed when the control has focus.

7
KeyPress

Occurs when a key is pressed when the control has focus.

8 KeyUp

Occurs when a key is released when the control has focus.

9
Leave

Occurs when input focus leaves the PictureBox.

10 LoadCompleted

Occurs when the asynchronous image-load operation is completed, been


canceled, or raised an exception.

11
LoadProgressChanged

Occurs when the progress of an asynchronous image-loading operation


has changed.

12 Resize

Occurs when the control is resized.

13 RightToLeftChanged

Occurs when the value of the RightToLeft property changes.

14
SizeChanged

Occurs when the Size property value changes.

15 SizeModeChanged

Occurs when SizeMode changes.

16 TabIndexChanged
Occurs when the value of the TabIndex property changes.

17
TabStopChanged

Occurs when the value of the TabStop property changes.

18
TextChanged

Occurs when the value of the Text property changes.

You might also like