UNIT 3
UNIT 3
NET UIBS
Prepared By
Sabnam Pradhan
Professor and Faculty of Computer Applications
Unit 4
Application Development on .NET:C#.NET: Building Windows Applications, VB.NET: Windows Forms.
Working with Controls, Timer, Picture-box, Group-box, Combo-box, Horizontal and Vertical Scrollbar,
Numeric-up-down, Track-bar, and Progress-bar. Subroutines and Functions in VB.NET. Database applications
----------------------------------------------------------------------------------------------------------------------------------------------------
Properties Description
BackColor It is used to set the background color for the form.
BackgroundImage It is used to set the background image of the form.
Cursor It is used to set the cursor image when it hovers over the form.
AllowDrop Using the AllowDrop control in a form, it allows whether to drag and drop on the
form.
Font It is used to get or set the font used in a form.
Locked It determines whether the form is locked or not.
FormBorderStyle It is used to set or get border style in a form.
Text It is used to set the title for a form window.
MinimizeBox MinimizeBox It is used to display the minimum option on the title bar of the
form.
IsMDIChild It is used to authenticate whether a form is a container of a Multiple Document
Interface (MDI) child form.
A Form uses a System.Windows.Form namespace, and it has a wide family of controls that add both
forms and functions in a Window-based user interface.
Top, Left It is used to set the top-left corner coordinates of the form in pixel.
Name It is used to define the name of the form.
MinimumSize It is used to set the minimum height and width of the form.
Enabled It uses the True or False value to enable mouse or keyboard events in the form.
TopMost It uses a Boolean value that represents whether you want to put the window form on
top of the other form. By default, it is False.
Form Events
The following are the most important list of events related to a form.
Events Description
Activated An activated event is found when the user or program activates the form.
Click A click event is active when the form is clicked.
Closed A closed event is found before closing the form.
Closing It exists when a form is closing.
DoubleClick
The DoubleClick event is activated when a user double clicks on the form.
DragDrop A DragDrop event is activated when a drag and drop operation is performed.
MouseDown A MouseDown event is activated when the mouse pointer is on the form, and the
mouse button is pressed.
GotFocus A GotFocus event is activated when the form control receives a focus.
HelpButtonClicked It is activated when a user clicked on the help button.
KeyDown A KeyDown event is activated when a key is pressed while focussing on the form.
KeyUp A KeyUp event is activated when a key is released while focusing on the form.
Load The load event is used to load a form before it is first displayed.
LostFocus It is activated when the form loses focus.
MouseEnter A MouseEnter event is activated when the mouse pointer enters the form.
MouseHover A MouseHover event is activated when the mouse pointer put on the form.
MouseLeave A MouseLeave event is activated when the mouse pointer leaves the form surface.
Shown It is activated whenever the form is displayed for the first time.
Scroll A Scroll event is activated when a form is scrolled through a user or code.
Resize A Resize event is activated when a form is resized.
Move A Move event is activated when a form is moved.
For creating a Windows Forms application in VB.NET, we need to follow the following steps in Microsoft
Visual Studio.
Form1.vb
' It is Label1
End Sub
' It is Label2
End Sub
nameStr = TextBox1.Text
num = TextBox2.Text
Label3.Text = "You have entered the Name " & nameStr + " Number " & num
End Sub
' It is label3
End Sub
End Class
Output: Now enter the following details in the form:
• After filling all the details, click on the Submit button. After that, it shows the following Output:
Let's create a label in the VB.NET Windows by using the following steps:
Step 1: We have to drag the Label control from the Toolbox and drop it on the Windows form, as shown
below.
Step 2: Once the Label is added to the form, we can set various properties to the Label by clicking on the
Label
control.
VB.NET Label Properties
Properties Description
AutoSize As the name defines, an AutoSize property of label control is used to set or get a
value if it is automatically resized to display all its contents.
Border Style It is used to set the style of the border in the Windows form.
PreferredWidth It is used to set or get the preferred width for the Label control.
Font It is used to get or set the font of the text displayed on a Windows form.
TextAlign It is used to set the alignment of text such as centre, bottom, top, left, or right.
ContextMenu It is used to get or sets the shortcut menu associated with the Label control.
ImageIndex It is used to set the index value to a label control displayed on the Windows form.
Events Descrip on
AutoSizeChanged An AutoSizeChanged event occurs in the Label control when the value of AutoSize property is
changed.
DoubleClick When a user performs a double-clicked in the Label control, the DoubleClick event occurs.
GotFocus It occurs when the Label Control receives focus on the Window Form.
Leave The Leave event is found when the input focus leaves the Label Control.
TabIndexChanged It occurs when the value of Tabindex property is changed in the Label control.
ControlRemoved When the control is removed from the Control.ControlCollec on, a ControlRemoved event,
occurs.
TabStopChanged It occurs when the property of TabStop is changed in the Label Control.
BackColorChanged A BackColorChanged event occurs in the Label control when the value of the BackColor
property is changed.
ControlAdded When a new control is added to the Control.ControlCollec on, a ControlAdded event occurs.
DragDrop A DragDrop event occurs in the Label control when a drag and drop opera on is completed.
Furthermore, we can also refer to the VB.NET Microsoft documentation to get a complete list of Label
properties and events.
Label.vb
Button1.Text = "Send"
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
RichTextBox1.Text = " "
End Sub
End Class
Output:
We have created 5 Labels on the Windows Form by using drag and drop operation in the above output.
Form1.vb
Output:
control.
Text It is used to get or set the text associated with the textbox control.
Visible The Visible property sets a value that indicates whether the textbox should be
displayed on a Windows Form.
WordWrap The WordWrap properties validate whether the multiline Textbox control
automatically wraps words to the beginning of the next line when necessary.
AcceptTabsChanged It is found in the TextBox control when the property value of the AcceptTab
is changed.
It is found in the TextBox Control when the property value of the BackColor is
BackColorChanged
BorderStyleChanged It is found in the TextBox Control when the value of the BorderStyle is
changed.
JavatPoint1.vb
JavatPoint1.vb
Label1.Text = "User Login Details" ' Set the title name for Label1
Text3.PasswordChar = "*"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click End ' terminate
the program when the user clinks button 2
End Sub
name = text1.Text
Uname = Text2.Text
pass = Text3.Text
MsgBox(" Your Name: " & name + vbCrLf + "Your UserName: " & Uname + vbCrLf + "Your Password:
" & pass)
End Sub
End Class
Output:
Now enter all the details of the User Login form, it shows the following image, as shown below.
Now, click on the Login button. It shows all the details filled by the user in
the form.
In VB.NET, we use the Date and Time function to perform various operations related to date and time.
Sometimes we need to display the date and time in our application or web application, such as when the last
post edited, upgradation of new software version or patch
-up details, etc.
In DateTime class, Date datatype stores date values, time values or date, and time values. Furthermore,
to perform the date and time function, we need to import the System.DateTimeclass. The default value of
DateTime is between 00:00:00 midnight
, Jan 1, 0001 to 11:59:59 P.M., Dec 31, 9999 A.D.
Day: It is used to return the day of the month represented by the DateTime object.
DayOfWeek: It is used to return a particular day of the week represented by the DateTime object.
Minute: The Minute property is used to return the minute component by the DateTime object.
DateOfYear: It is used to return a day of the year represented by the DateTime object.
Hour: It is used to return the hour of the component of the date represented by the DateTime object.
Now: It is used to return the current date and time of the local system.
Month: The Month property is used to return the month name of the Datetime object.
Second: It is used to return the second of the DateTime object.
Ticks: It is used to return the number of ticks that refer to the DateTime object.
Year: It is used to return the year of the date represented by the DateTime object.
TimeOfDay: It is used to return the time of the day represented by the DateTime object.
Methods
The following are the most commonly used methods of the DateTime.
DaysInMonth: The DaysInMonth m ethod is used to return the total number of days in the specified month of
the year.
Add: It is used to return a new DateTime value by adding the timespan value to the DateTime object value.
AddHours: It is used to return a new time by adding the hours to the value of the Datetime object.
AddYears: It is used to return the year by adding the year to the value of the DateTime object.
AddDays: It is used to return the new Day by adding the days to the value of the DateTime object.
AddMinutes: It is used to display the new time by adding the minutes to the Datetime object.
AddMonths: It is used to return the new time by adding the months to the value of the Datetime object.
AddSeconds: It is used to return the new time by adding the seconds to the value of the Datetime object.
IsLeapYear: It uses a Boolean value that represents whether the particular year is a leap year or not.
Here, DateTime is a class for creating objects with the new keyword, and obj_name is the name of the
object.
Let us create a program to show the different functions of DateTime ClassVB.NE
in T.
DiffDateTime.vb
The ComboBoxcontrol is used to display more than one item in a drop-down list. It is a combination
of Listbox and Textbox in which the user can input only one item. Furthermore, it also allows a user to select
an item from a drop-down list.
Let us create a ComboBox control in the VB.NET Windows by using the following steps.
Step 1: We need to drag the combo box control from the toolbox and drop it to theWindows form, as shown
below.
Step 2: Once the ComboBox is added to the form, we can set various properties of the ComboBox by
clicking
ComboBox Properties
There are following properties of the ComboBox control.
Property Description
AllowSelection The AllowSelection property takes the value that indicates whether the list
allows selecting the list item.
AutoCompleteMode It takes a value that represents how automatic completion work for the ComboBox.
Created It takes a value that determines whether the control is created or not.
BackColor The BackColor property is used to set the background color of the combo box control.
DataSource It is used to get or set the data source for a ComboBox Control.
FlatStyle It is used to set the style or appearance for the ComboBox Control.
MaxDropDownItems The MaxDropDownItems property is used in the combo box control to display
the maximum number of items by setting a value.
MaxLength It is used by the user to enter maximum characters in the editable area of the
combo box.
SelectedItem It is used to set or get the selected item in the ComboBox Control.
Sorted The Sorted property is used to sort all the items in the ComboBox by setting the value.
ComboBox Events
Events Description
FontChanged It occurs when the property of the font value is changed.
Format When the data is bound with a combo box control, a format event is called.
SelectIndexChanged It occurs when the property value of SelectIndexChanged is changed.
HelpRequested When the user requests for help in control, the HelpRequested event is called.
Leave It occurs when the user leaves the focus on the ComboBox Control.
MarginChanged It occurs when the property of margin is changed in the ComboBox control.
ComboBox Events
Let us create a program to display the Calendar in the VB.NET Windows Form.
ComboBox_Control.vb
ComboBox2.Items.Add("Month")
ComboBox2.Items.Add("January")
ComboBox2.Items.Add("February")
ComboBox2.Items.Add("March")
ComboBox2.Items.Add("May")
ComboBox2.Items.Add("June")
ComboBox2.Items.Add("July")
ComboBox3.Items.Add("Year")
ComboBox3.Items.Add("2016")
ComboBox3.Items.Add("2017")
ComboBox3.Items.Add("2018")
ComboBox3.Items.Add("2019")
ComboBox3.Items.Add("2020")
End Sub
Output:
Now select the day, month, and year from dropdown box and then click on the Date button to display thee date
the form. in
CanSelect It obtains a value that determines whether the Listbox control can be selected.
ColumnWidth It is used to get or set the width of the columns in a multicolumn Listbox.
Container As the name defines, a container gets the IContainer that stores the component of
ListBox control.
Controls It is used to get the collection of controls contained within the control.
Step 1: Drag the ListBox control from the Toolbox and drop it to the Window s form, as shown below.
Step 2: Once the ListBox is added to the Form, we can set various properties of the Listbox by clicking on the
ListBox control.
ListBox Properties
Created It takes a value that determines whether the control is created or not.
Width It is used to set the width of the ListBox control.
Visible It takes a value that determines whether the ListBox control and all its child are
displayed on the Windows Form.
SelectionMode It is used to get or set the method that determines which items are selected in the
ListBox.
MultiColumn It allows multiple columns of the item to be displayed by setting the True value in the
Listbox.
ListBox Methods
Clear It is used to remove all items from the item collection at the same time.
Contains It is used to check whether the particular item exists in the ListBox or not.
Show() It is used to display the control to the user.
Sort() As the name suggests, a Sort() method is used to arrange or sort the elements in the
ListBox.
ResetText() A ResetText() method is used to reset ListBox's text property and set the default
value.
ResetBackColor() It is used to reset the backColor property of the ListBox and set the default value.
OnNotifyMessage It is used to notify the message of the ListBox to Windows.
GetSelected The GetSelected method is used to validate whether the specified item is selected.
Furthermore, we can also refer to VB.NET Microsoft documentation to get a complete list of ListBox
properties, and methods.
Let's create a program to select an item from the ListBox in the VB.NET form.
Listbx.vb
Output:
Click on the Show button to display the selected item in Windows Form, as
follows.
Step 1: We need to drag the combo box control from the toolbox and drop it to the Window s form, as shown
below.
Step 2: Once the Com boBox is added to the form, we can set various properties of the ComboBox by clicking
on the ComboBox control.
ComboBox Properties
Property Description
AllowSelection The AllowSelection property takes the value that indicates whether the list
allows selecting the list item.
AutoCompleteMode It takes a value that represents how automatic completion work for the
ComboBox.
Created It takes a value that determines whether the control is created or not.
DataBinding It is used to bind the data with a ComboBox Control.
BackColor The BackColor property is used to set the background color of the combo
box
There are following properties
of the ComboBox control.
MaxLength It is used by the user to enter maximum characters in the editable area of the combo
box.
SelectedItem It is used to set or get the selected item in the ComboBox Control.
Sorted The Sorted property is used to sort all the items in the ComboBox by setting the value.
Dim YY As Integer
Private Sub ComboBox_Control_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "JavaTpoint.com"
Label1.Text = "Display Calendar"
Label2.Text = "Get Date"
ComboBox Events
Events Description
FontChanged It occurs when the property of the font value is changed.
Format When the data is bound with a combo box control, a format event is called.
SelectIndexChanged It occurs when the property value of SelectIndexChanged is changed.
HelpRequested When the user requests for help in control, the HelpRequested event is called.
Leave It occurs when the user leaves the focus on the ComboBox Control.
MarginChanged It occurs when the property of margin is changed in the ComboBox control.
ComboBox_Control.vb
PublicClassComboBox_Control
Dim DT As Integer
Dim MM As String
Button1.Text = "Date"
Button2.Text = "Exit"
ComboBox1.Items.Add("Date")
ComboBox1.Items.Add("01")
ComboBox1.Items.Add("02")
ComboBox1.Items.Add("03")
ComboBox1.Items.Add("04")
ComboBox1.Items.Add("05")
ComboBox1.Items.Add("06")
ComboBox1.Items.Add("07")
ComboBox1.Items.Add("08")
ComboBox1.Items.Add("09")
ComboBox2.Items.Add("Month")
ComboBox2.Items.Add("January")
ComboBox2.Items.Add("February")
ComboBox2.Items.Add("March")
ComboBox2.Items.Add("May")
ComboBox2.Items.Add("June")
ComboBox2.Items.Add("July")
ComboBox3.Items.Add("Year" )
ComboBox3.Items.Add("2016")
ComboBox3.Items.Add("2017")
ComboBox3.Items.Add("2018")
ComboBox3.Items.Add("2019")
ComboBox3.Items.Add("2020")
End Sub
Output:
Now select the day, month, and year from dropdown box and then click on the Date button to display th e date in
the form.
RadioButton Control
The RadioButton is used to select one option from the number of choices. If we want to select only one
item from a related or group of items in the windows forms, we can use the radio button. The RadioButton is
mutually exclusive that represents only one item is active and the remains unchecked in the form.
Let us create a RadioButton control in the VB.NET Windows by using the following steps.
Step 1: Drag the RadioButton control from the toolbox and drop it to the Window s form, as shown below.
Appearance It is used to get or set a value that represents the appearance of the RadioButton.
AutoScrollOffset It is used to get or set the radio control in ScrollControlIntoView(Control).
AutoCheck The AutoCheck property is used to check whether the checked value or appearance of
control can be automatically changed when the user clicked on the RadioButton control.
AutoSize The AutoSize property is used to check whether the radio control can be automatically
resized by setting a value in the RadioButton control.
CanSelect A CanSelect property is used to validate whether a radio control can be selected by setting
a value in the RadioButton control.
CheckAlign It is used to obtain or set a value that indicates the location of the check portion in the
radioButton control.
Text The Text property is used to set the name of the RadioButton control.
Step 2: Once the RadioButton is added to the form, we can set various properties of the RadioButton by
clicking on the Radio control.
RadioButton Properties
There are following properties of the VB.NET RadioButton control.
GetAutoSizeMode() It is used to return a value that represents how the control will operate when the
AutoSize property is enabled in the RadioButton control of the Window form.
RadioButton Methods
ResetText() As the name suggests, a ResetText() method is used to reset the property of text to its
default value or empty.
Update() It is used to reroute an invalid field, which causes control in the client region.
We can also refer to Microsoft documentation to get a complete list of RadioButton Control properties and
methods in the VB .NET.
Let us create a program to understand the uses of Radio button control in the VB.NET form.
RadioBtn.vb
End Sub
Click on the Submit button. It shows the following message on the screen.
Let's create a ScrollBar control in the VB.NET Windows form using the following steps.
Step 1: The first step is to drag the HS crollBar and VScrollBar control from the toolbox and drop it on to the
form.
Step 2: Once the ScrollBar is added to the form, we can set various properties of the ScrollBar by clicking on
the HScrollBar and VScrollBar control.
Property Description
BackColor The BackColor property is used to set the back color of the scroll bar.
Maximum It is used to set or get the maximum value of the Scroll Bar control. By default, it is 100.
Minimum It is used to get or set the minimum value of the Scroll bar control. By default, it is 0.
SmallChange It is used to obtain or set a value that will be added or subtracted from the property of the
scroll bar control when the scroll bar is moved a short distance.
AutoSize As the name suggests, the AutoSize property is used to get or set a value representing
whether the scroll bar can be resized automatically or not with its contents.
LargeChange It is used to obtain or set a value that will be added or subtracted from the property of the
scroll bar control when the scroll bar is moved a large distance.
Value It is used to obtain or set a value in a scroll bar control that indicates a scroll box's current
position.
DefaultImeMode It is used to get the default input method Editor (IME) that are supported by ScrollBar
controls in the Windows Form.
Method Description
UpdateScrollInfo It is used to update the ScrollBar control using the Minimum, maximum, and
the value of LargeChange properties.
Event Description
AutoSizeChanged The AutoSizeChanged event is found in the ScrollBar control when the value of the
AutoSize property changes.
Scroll The Scroll event is found when the Scroll control is moved.
TextChangedEvent It occurs in the ScrollBar control when the value of the text property changes.
ValueChanged A ValueChanged event occurs when the property of the value is changed
programmatically or by a scroll event in the Scrollbar Control.
Properties of the ScrollBar Control Methods of the ScrollBar Control Events of the
ScrollBar Control
Furthermore, we can also refer to VB.NET Microsoft documentation to get a complete list of ScrollBar control
properties, methods, and events in the VB.NET.
Let us create a simple program to understand the use of ScrollBar Control in the VB.NET Windows Forms.
ScrollBar.vb
Me.VScrollBar1.BackColor = Color.Blue
Me.HScrollBar1.Minimum = 0
Me.HScrollBar1.Maximum = 100
Me.HScrollBar1.Value = 35
End Sub
End Class
Output:
.NET is a software framework that is designed and developed by Microsoft. The first version of the
.Net framework was 1.0 which came in the year 2002. In other words, it is a virtual machine for compiling
and executing programs written in different languages like C#, VB.Net, etc.
Structure of Subprocedure:
Sub <subname> [(parameter list)]
Vb statements
End Sub
Example:
Module module1
Sub SubDivide(ByVal num1 As Integer,
res = num1/num2
Else
End If
End Sub
Sub Main()
Dim a As Integer
Dim b As Integer
Console.Write("Enter
Number 1") a =
Console.ReadLine()
Console.Write("Enter
Number 2") b =
Console.ReadLine()
SubDivide(a, b)
Console.WriteLine(res)
End Sub
End Module
Output:
FunctionProcedures:
A function procedure is a group of VB.NET statements. It begins with a Function keyword and
ends with an End Function keyword. It is generally used to perform a task and return a value back to the
calling code. It may have multiple return points to the calling code. A part from return stamens, End
Function, or Exit function also returns control to the calling procedure.
Vb statements
End Function
Example:
Module module1
res = num1/num2
return res
Else
End If
End Function
Sub Main()
Dim a As Integer
Dim b As Integer
a = Console.ReadLine()
b = Console.ReadLine()
res = FunctionDivide(a, b)
Console.WriteLine(res)
End Sub
End Module