Pre-Assessment Questions: Working With Windows Forms
Pre-Assessment Questions: Working With Windows Forms
Pre-Assessment Questions
1. Which of the following is not included in the user interfaces provided by .NET
framework?
a. Web forms
b. Windows forms
c. Console applications
d. Web services
Solutions to Pre-Assessment
Questions
1. d.
2. d.
3. d
4. d.
5. a.
Objectives
In this lesson, you will learn to:
• List the features of Windows Forms
• Identify different form controls
• List the different language features required to work with Windows Forms
• Create Windows Forms
• Validate data in Windows Forms
When you create a new project for a Windows application, a form is automatically
added to the project. This form has the default name Form1.vb.
Form Controls
• A Form Control
• is a component used to accept input from the user or display some
information on the form.
• has its own set of properties, methods, and events that makes it suitable
for a particular task.
• can be added to a Windows Form by dragging the control from the toolbox
and placing it on the form at the required location.
• can also be loaded on the Windows Form by double-clicking the control on
the toolbox.
Label
Control TextBox
Control
ListBox
Control
GroupBox
Control
CheckBox
Control
Button
Control
StatusBar
Control
• Mouse events
• MouseDown
• MouseUp
• MouseMove
• Control-specific events
• Resize
• VisibleChanged
Data Types
• The data used by an application may be of different types.
• The important data types provided by VB .NET to store different types
of data are:
• Byte
• Short
• Integer
• Long (long integer)
• Single
• Double
• Decimal
• Boolean
• Char
• String
• Date
• Object
©NIIT Introduction to VB .NET Lesson 1B / Slide 29 of 43
Working With Windows Forms
Variables
• VB .NET allows you to use variables for temporarily storing data at run time.
• A variable has a
• Name: used to access and manipulate the value of the variable.
• Data type: determines the type of data that the variable can store.
• The Dim statement is used to declare variables.
• You can specify the name of a variable and the type of storage in the Dim
statement.
• The data type for the variable is defined by using the As clause of the Dim
statement.
A variable can be defined using:
• A system data type, such as Boolean, String, or Integer
• A composite data type, such as an array or a structure
• An object type, such as Label or TextBox
Arrays
• An array is a collection of values of the same data type.
• The variables in an array are called array elements.
• Array elements are accessed using a single name and an index number
representing the position of the element within the array.
• In VB .NET, the array subscript always starts with zero.
Arrays (Contd.)
• Declaring an Array: You can declare an array by using the following syntax:
Dim arrayname(Number-of-elements) as datatype
You can also create multidimensional arrays.
• Assigning Values to Array Elements: You can assign values to each element
of an array by using the index number (also called the array subscript) of the
element. Example: Score(0) = 5
This statement assigns the value 5 to the first element of the array, Score.
• Resizing an Array: You can resize an array by using the ReDim statement.
However, when you use the ReDim statement, the existing contents are
erased. You can use the Preserve keyword to ensure that the existing
contents of an array are not lost when you use the ReDim statement.
Example: ReDim Score(20)
This statement resizes the Score array to hold 20 elements.
Operators
• Applications use operators to process the data entered by a user.
• Arithmetic Operators: Arithmetic operators are used to perform arithmetic
operations on variables.
• +
• -
• *
• ^
• /
• \
• Mod
Operators (Contd.)
• Comparison Operators: Comparison operators are used to compare two
values and perform an action based on the result of the comparison.
• <
• >
• <=
• >=
• =
• <>
Operators (Contd.)
• Logical operators: Logical operators are used to evaluate expressions and
return a Boolean value.
• And
• Not
• Or
• Xor
• OrElse
• AndAlso
Operators (Contd.)
• Concatenation Operators: Concatenation Operators are used to join two
expressions.
• &
• +
Demo
Creating Windows Forms
Problem Statement
Solution
Summary
In this lesson, you learned that:
• A form is used to accept input from the user and present information to the
user.
• A Windows Form has many properties, methods and events.
• An event gets generated on performing an action such as clicking the mouse
or pressing a key from the keyboard.
• When an event is raised, the code within the event handler is executed.
• Controls can be added to a form to accept input from the user or display
some information on the form.
• Some commonly used controls are TextBox, Label, CheckBox, RadioButton,
and Button.
• Controls can be added at design time or at runtime.
• Variables are used to store data at run time. You can declare a variable by
using the Dim keyword.
• VB .NET provides the many data types, such as, Byte, Short, Integer, Long,
Single etc.
Summary (Contd.)
• The decision structures supported by Visual Basic .NET include:
• If-Then-Else
• Select-Case
• The loop structures supported by Visual Basic .NET are:
• While-End While
• Do-Loop
• For-Next
• The data validation in a windows form can be performed by using
ErrorProvider control.