Unit 4
Unit 4
Reports – Distributing Application – Table Operations – Data Storage Methods – Storing Data
Columns – Data Clustering and Partitioning.
Forms Events
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.
Every form will have title bar on which the form's caption is displayed and
there will be buttons to close, maximize and minimize the form shown below
−
If you click the icon on the top left corner, it opens the control menu, which
contains the various commands to control the form like to move control from
one place to another place, to maximize or minimize the form or to close the
form.
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.
Properties Description
N
The button that's automatically activated when you hit the Esc key.
2 CancelButton 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.
AutoScrollMinSiz This property lets you specify the minimum size of the form,
5
e before the scroll bars are attached.
By default, this property is True and you can set it to False to hide
9 ControlBox
the icon and disable the Control menu.
By default, this property is True and you can set it to False to hide
14 MinimizeBox
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.
This specifies the minimum height and width of the window you
16 MinimumSize
can minimize.
This specifies the maximum height and width of the window you
17 MaximumSize
maximize.
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
19 StartPosition
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.
These two properties set or return the coordinates of the form's top-
21 Top, Left
left corner in pixels.
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
.
Activate
1
Activates the form and gives it focus.
ActivateMdiChild
2
Activates the MDI child of a form.
AddOwnedForm
3
Adds an owned form to this form.
BringToFront
4
Brings the control to the front of the z-order.
CenterToParent
5
Centers the position of the form within the bounds of the parent form.
CenterToScreen
6
Centers the form on the current screen.
Close
7
Closes the form.
Contains
8
Retrieves a value indicating whether the specified control is a child of the control.
Focus
9
Sets input focus to the control.
Hide
10
Conceals the control from the user.
Refresh
11 Forces the control to invalidate its client area and immediately redraw itself and any child
controls.
Scale(SizeF)
12
Scales the control and all child controls by the specified scaling factor.
ScaleControl
13
Scales the location, size, padding, and margin of a control.
ScaleCore
14
Performs scaling of the form.
Select
15
Activates the control.
SendToBack
16
Sends the control to the back of the z-order.
SetAutoScrollMargin
17
Sets the size of the auto-scroll margins.
SetDesktopBounds
18
Sets the bounds of the form in desktop coordinates.
SetDesktopLocation
19
Sets the location of the form in desktop coordinates.
SetDisplayRectLocation
20
Positions the display window to the specified value.
Show
21
Displays the control to the user.
ShowDialog
22
Shows the form as a modal dialog box.
Explore our latest online courses and learn new skills at your own pace.
Enroll and become a certified expert to boost your career.
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
.
HelpButtonClicke
9 Occurs when the Help button is clicked.
d
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.
Occurs when the mouse pointer is over the form and a mouse
15 MouseDown
button is pressed.
19 MouseMove Occurs when the mouse pointer is moved over the form.
Occurs when the mouse pointer is over the form and a mouse
20 MouseUp
button is released.
Occurs when the mouse wheel moves while the control has
21 MouseWheel
focus.
24 Scroll Occurs when the user or code scrolls through the client area.
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 Forms
The container for all the controls that make up the user interface.
2 TextBox
It represents a Windows text box control.
3 Label
It represents a standard Windows label.
4 Button
It represents a Windows button control.
5 ListBox
It represents a Windows control to display a list of items.
6 ComboBox
It represents a Windows combo box control.
RadioButton
7 It enables the user to select a single option from a group of choices when paired with other
RadioButton controls.
8 CheckBox
It represents a Windows CheckBox.
9 PictureBox
It represents a Windows picture box control for displaying an image.
10 ProgressBar
It represents a Windows progress bar control.
11 ScrollBar
It Implements the basic functionality of a scroll bar control.
DateTimePicker
12 It represents a Windows control that allows the user to select a date and a time and to
display the date and time with a specified format.
13 TreeView
It displays a hierarchical collection of labeled items, each represented by a TreeNode.
ListView
14 It represents a Windows list view control, which displays a collection of items that can be
displayed using one of four different views.
When you double click any of the dialog controls in the toolbox or drag the
control onto the form, it appears in the Component tray at the bottom of the
Windows Forms Designer, they do not directly show up on the form.
The following table lists the commonly used dialog box controls. Click the
following links to check their detail −
Sr.No
Control & Description
.
ColorDialog
1 It represents a common dialog box that displays available colors along with controls that
enable the user to define custom colors.
FontDialog
2 It prompts the user to choose a font from among those installed on the local computer and
lets the user select the font, font size, and color.
OpenFileDialog
3
It prompts the user to open a file and allows the user to select a file to open.
SaveFileDialog
4 It prompts the user to select a location for saving a file and allows the user to specify the
name of the file to save data.
PrintDialog
5 It lets the user to print documents by selecting a printer and choosing which sections of the
document to print from a Windows Forms application.
Data Provider
A data provider is used for connecting to a database, executing commands
and retrieving data, storing it in a dataset, reading the retrieved data and
updating the database.
Sr.No
Objects & Description
.
Connection
1
This component is used to set up a connection with a data source.
Command
2 A command is a SQL statement or a stored procedure used to retrieve, insert, delete or
modify data in a data source.
3 DataReader
Data reader is used to retrieve data from a data source in a read-only and forward-only
mode.
DataAdapter
This is integral to the working of ADO.Net since data is transferred to and from a database
4 through a data adapter. It retrieves data from a database into a dataset and updates the
database. When changes are made to the dataset, the changes in the database are actually
done by the data adapter.
The .Net Framework data provider for SQL Server - provides access to
Microsoft SQL Server.
The .Net Framework data provider for OLE DB - provides access to data
sources exposed by using OLE DB.
The .Net Framework data provider for ODBC - provides access to data
sources exposed by ODBC.
The .Net Framework data provider for Oracle - provides access to
Oracle data source.
The EntityClient provider - enables accessing data through Entity Data
Model (EDM) applications.
Explore our latest online courses and learn new skills at your own pace.
Enroll and become a certified expert to boost your career.
DataSet
DataSet is an in-memory representation of data. It is a disconnected, cached
set of records that are retrieved from a database. When a connection is
established with the database, the data adapter creates a dataset and stores
data in it. After the data is retrieved and stored in a dataset, the connection
with the database is closed. This is called the 'disconnected architecture'. The
dataset works as a virtual database containing tables, rows, and columns.
Sr.No
Components & Description
.
DataTableCollection
1
It contains all the tables retrieved from the data source.
DataRelationCollection
2
It contains relationships and the links between tables in a data set.
ExtendedProperties
3 It contains additional information, like the SQL statement for retrieving data, time of
retrieval, etc.
DataTable
4 It represents a table in the DataTableCollection of a dataset. It consists of the DataRow
and DataColumn objects. The DataTable objects are case-sensitive.
DataRelation
5 It represents a relationship in the DataRelationshipCollection of the dataset. It is used to
relate two DataTable objects to each other through the DataColumn objects.
DataRowCollection
6
It contains all the rows in a DataTable.
DataView
7 It represents a fixed customized view of a DataTable for sorting, filtering, searching,
editing and navigation.
PrimaryKey
8
It represents the column that uniquely identifies a row in a DataTable.
DataRow
It represents a row in the DataTable. The DataRow object and its properties and methods
9
are used to retrieve, evaluate, insert, delete, and update values in the DataTable. The
NewRow method is used to create a new row and the Add method adds a row to the table.
DataColumnCollection
10
It represents all the columns in a DataTable.
DataColumn
11
It consists of the number of columns that comprise a DataTable.
Connecting to a Database
The .Net Framework provides two types of Connection classes −
Example 1
We have a table stored in Microsoft SQL Server, named Customers, in a
database named testDB. Please consult 'SQL Server' tutorial for creating
databases and database tables in SQL Server.
Choose the database object, Customers table in our example, and click
the Finish button.
Select the Preview Data link to see the data in the Results grid −
When the application is run using Start button available at the Microsoft
Visual Studio tool bar, it will show the following window −
Example 2
In this example, let us access data in a DataGridView control using code.
Take the following steps −
Me.CUSTOMERSTableAdapter.Fill(Me.TestDBDataSet.CUSTOMERS)
' Set the caption bar text of the form.
Me.Text = "tutorialspoint.com"
End Sub
Clicking the Fill button displays the table on the data grid view control
−
Clicking the Fill button displays the table on the data grid view control
−