SlideShare uma empresa Scribd logo
1 de 43
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

    1.   Which of the following information is not stored in Assemblies?
         a.  Name of the assembly
         b.  Version number of the assembly
         c.  Security information
         d.  Type-safety checks




 ©NIIT                   Introduction to VB .NET             Lesson 1B / Slide 1 of 43
Working With Windows Forms


Pre-Assessment Questions (Contd.)
    1.   The Visual Studio .NET IDE provides three navigational features. Which of
         the following is not the navigational feature provided by .NET?
         a.   Docking
         b.   Tabbed Navigation
         c.   Auto Hide
         d.   Auto Visible

    1.   CLR enforces restrictions on managed code to provide Code Access Security.
         This is done through the use of objects. These objects are called
         a.    GAC
         b.    CTS
         c.    CLS
         d.    Permissions



 ©NIIT                   Introduction to VB .NET            Lesson 1B / Slide 2 of 43
Working With Windows Forms


Pre-Assessment Questions (Contd.)
    1.   The capability of a derived class to hide the characteristics of the parent class
         is called
         a.    Overriding
         b.    Overloading
         c.    Structured programming
         d.    Inheritance




 ©NIIT                    Introduction to VB .NET              Lesson 1B / Slide 3 of 43
Working With Windows Forms


Solutions to Pre-Assessment
Questions
         1.   d.
         2.   d.
         3.   d
         4.   d.
         5.   a.




 ©NIIT             Introduction to VB .NET   Lesson 1B / Slide 4 of 43
Working With Windows Forms


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




 ©NIIT                  Introduction to VB .NET            Lesson 1B / Slide 5 of 43
Working With Windows Forms


Getting Started With Windows Forms
    •    A user interface is the means by which a user interacts with an application.
    •    Two types of user interfaces are:
           • Character user interface (CUI):
           • Graphical user interface (GUI):
    •    User interaction in a Windows-based application is accomplished through
         Windows Forms and controls.




 ©NIIT                     Introduction to VB .NET             Lesson 1B / Slide 6 of 43
Working With Windows Forms


Introducing Windows Forms
    •    A Windows Form
           • is a representation of any window displayed in an application.
           • is used to accept input from a user and display information.
           • is a class derived from Form class in System.Windows.Forms namespace.
           • can also be inherited from the existing forms in the project to change the
             existing behavior.
           • inherits many predefined properties, methods, and events associated with
             its base classes.




 ©NIIT                     Introduction to VB .NET            Lesson 1B / Slide 7 of 43
Working With Windows Forms


Introducing Windows Forms (Contd.)
The following figure shows a sample Windows Form for accepting login details from a
user:




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.


 ©NIIT                   Introduction to VB .NET            Lesson 1B / Slide 8 of 43
Working With Windows Forms


Windows Forms Properties
    •    Windows Form properties are used to determine its appearance at run time.
    •    The commonly used properties of a Windows Form are:
           • Name
           • BackColor
           • BackgroundImage
           • Font
           • Size
           • StartPosition
           • Text
           • WindowState




 ©NIIT                    Introduction to VB .NET           Lesson 1B / Slide 9 of 43
Working With Windows Forms


Windows Forms Events
    •    An event is generated when a user performs an action, such as clicking the
         mouse or pressing a key.
    •    Each form and control has a predefined set of events associated with it.


    •    The common events used in a Windows Form are:
           • Click
           • Closed
           • Deactivate
           • Load
           • MouseMove
           • MouseDown
           • MouseUp




 ©NIIT                    Introduction to VB .NET           Lesson 1B / Slide 10 of 43
Working With Windows Forms


Windows Forms Events (Contd.)
    •    Event handler is a special method that specifies the action to be performed on
         the occurrence of an event.
    •    You can add the code for an event handler by using the Code Editor window
         as shown in the following figure:




 ©NIIT                     Introduction to VB .NET           Lesson 1B / Slide 11 of 43
Working With Windows Forms


Windows Forms Events (Contd.)
    •    The following example shows an event handler for the Load event of Form1:

                    Private Sub Form1_Load(ByVal sender
                    As System.Object, ByVal e As
                    System.EventArgs) Handles
                    MyBase.Load
                             ’Code for initialization
                    of form variables
                    End Sub


    •    In the given sample code:
           • sender provides a reference to the object that raised the event
           • e passes an object-specific input, such as the location of the mouse and
              the type of mouse event for the event being handled.



 ©NIIT                     Introduction to VB .NET           Lesson 1B / Slide 12 of 43
Working With Windows Forms


Windows Forms Methods
    •    Windows Form methods allow you to perform various tasks, such as opening,
         activating, and closing the form.
    •    The commonly used methods are:
           • Show()
           • Activate()
           • Close()
           • SetDesktopLocation()




 ©NIIT                    Introduction to VB .NET         Lesson 1B / Slide 13 of 43
Working With Windows Forms


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.




 ©NIIT                    Introduction to VB .NET           Lesson 1B / Slide 14 of 43
Working With Windows Forms


Form Controls (Contd.)
  The following figure shows some controls:
                                                TextBox Control- Multiline
                                                      property set




                    Label
                   Control                                                         TextBox
                                                                                   Control




                 ListBox
                 Control


                 GroupBox
                 Control
                                                                                  CheckBox
                                                                                  Control

                 Button
                 Control

                 StatusBar
                 Control




 ©NIIT                       Introduction to VB .NET                         Lesson 1B / Slide 15 of 43
Working With Windows Forms


The TextBox Control
    •    The TextBox control is used to display text to a user or accept input from a
         user.
    •    By default, you can enter a maximum of 2048 characters in a TextBox
         control.
    •    The commonly used properties of the TextBox control are:
           • Text
           • MultiLine
           • PasswordChar




 ©NIIT                     Introduction to VB .NET           Lesson 1B / Slide 16 of 43
Working With Windows Forms


The Label Control
    •    The Label control
           • is used to display the text that cannot be edited by the user directly.
           • is used for providing information or description of another control on the
             Windows Form.
    •    The commonly used properties of the Label control are:
           • Text
           • AutoSize




 ©NIIT                     Introduction to VB .NET            Lesson 1B / Slide 17 of 43
Working With Windows Forms


The LinkLabel Control
    •    The LinkLabel control is used to display the text as a link to another form or
         Web site.
    •    The LinkLabel control has all properties of a Label control.
    •    The commonly used additional properties are:
           • LinkColor
           • ActiveLinkColor
           • DisabledLinkColor
           • LinkVisited




 ©NIIT                     Introduction to VB .NET            Lesson 1B / Slide 18 of 43
Working With Windows Forms


The ListBox Control
    •    The ListBox control is used to display a list of items to a user.
    •    A user can select an item from the list.
    •    You can add items to a ListBox control by using the properties window.
    •    The commonly used properties of the ListBox control are:
           • SelectionMode
           • Sorted
           • SelectedIndex
           • SelectedItem




 ©NIIT                    Introduction to VB .NET           Lesson 1B / Slide 19 of 43
Working With Windows Forms


The ComboBox Control
    •    The ComboBox control
           • is used to display a drop-down list of items.
           • is a combination of a text box in which a user enters an item and a drop-
             down list from which a user selects an item.
           • can be populated using the Properties window.
    •    The commonly used properties of the ComboBox control are:
           • Text
           • Sorted
           • SelectedIndex
           • SelectedItem




 ©NIIT                     Introduction to VB .NET           Lesson 1B / Slide 20 of 43
Working With Windows Forms


The CheckBox Control
    •    The CheckBox control is used to set Yes/No or True/false options.
    •    The commonly used properties of the CheckBox control are:
           • Text
           • Checked




 ©NIIT                    Introduction to VB .NET          Lesson 1B / Slide 21 of 43
Working With Windows Forms


The RadioButton Control
    •    The RadioButton control is used to provide a set of mutually exclusive options
         to the user.
    •    Only one radio button can be selected in a group.
    •    The commonly used properties of the RadioButton control are:
           • Text
           • Checked




 ©NIIT                    Introduction to VB .NET           Lesson 1B / Slide 22 of 43
Working With Windows Forms


The GroupBox Control
    •    The GroupBox control
           • is used to group related controls together.
           • facilitates the group of controls to be easily moved together at design
             time.
    •    You can specify the caption to be displayed for a GroupBox control by setting
         the Text property at runtime as follows:


                     GroupBox1.Text = “Select Gender”




 ©NIIT                    Introduction to VB .NET           Lesson 1B / Slide 23 of 43
Working With Windows Forms


The Button Control
    •    The Button control is used to perform an action when a user clicks it.
    •    The Button control has the Text property, which is used to display text on a
         button.
    •    You can also set the Text property at run time, as shown below:
                      GroupBox1.Text = “Select Gender”




 ©NIIT                     Introduction to VB .NET           Lesson 1B / Slide 24 of 43
Working With Windows Forms


The StatusBar Control
    •    The StatusBar control is used to display the status information at the bottom
         of the form.
    •    The commonly used properties of the StatusBar control are:
            • ShowPanels
            • Text
    •    You can display different text in different panels of a StatusBar control by
         following steps:
            • set the ShowPanels property to True.
            • add the text for each panel of the StatusBar control by using the Panels
               collection.




 ©NIIT                     Introduction to VB .NET           Lesson 1B / Slide 25 of 43
Working With Windows Forms


Form Controls (Contd.)
    •    The events associated with various controls can be categorized as follows:
           • Keyboard events
               • KeyDown
               • KeyUp
               • KeyPress

          •   Mouse events
                • MouseDown
                • MouseUp
                • MouseMove

          •   Control-specific events
                • Resize
                • VisibleChanged

 ©NIIT                      Introduction to VB .NET          Lesson 1B / Slide 26 of 43
Working With Windows Forms


Dynamically Loading Controls in
Windows Forms
    •    The loading of controls at runtime is called as dynamic loading of controls.
    •    Every control is a class derived from the System.Windows.Forms.Control
         class.
    •    Whenever you load a control from the toolbox in the form, an object of the
         class is created.
    •    Example: To dynamically load a text box, you need to specify the following
         code in the Form1_Load event of the Windows Form:
              Dim Txt1 As TextBox = New TextBox()
              Form1.Controls.Add(Txt1)
         The text box, Txt1 will be shown in the upper-left corner of the Form1.




 ©NIIT                   Introduction to VB .NET            Lesson 1B / Slide 27 of 43
Working With Windows Forms


Introducing VB .NET Language
Fundamentals
         •   VB .NET provides a number of language features. The fundamental
             features are:
             • Data types
             • Variables
             • Arrays
             • Operators
             • Control Flow Constructs




 ©NIIT                 Introduction to VB .NET          Lesson 1B / Slide 28 of 43
Working With Windows Forms
                                
                                

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


 ©NIIT                    Introduction to VB .NET            Lesson 1B / Slide 30 of 43
Working With Windows Forms


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.




 ©NIIT                  Introduction to VB .NET          Lesson 1B/ Slide 31 of 43
Working With Windows Forms


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.




 ©NIIT                   Introduction to VB .NET            Lesson 1B/ Slide 32 of 43
Working With Windows Forms


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




 ©NIIT                  Introduction to VB .NET          Lesson 1B / Slide 33 of 43
Working With Windows Forms


Operators (Contd.)
    •    Comparison Operators: Comparison operators are used to compare two
         values and perform an action based on the result of the comparison.
         • <
         • >
         • <=
         • >=
         • =
         • <>




 ©NIIT                 Introduction to VB .NET        Lesson 1B / Slide 34 of 43
Working With Windows Forms


Operators (Contd.)
    •    Logical operators: Logical operators are used to evaluate expressions and
         return a Boolean value.
         • And
         • Not
         • Or
         • Xor
         • OrElse
         • AndAlso




 ©NIIT                  Introduction to VB .NET          Lesson 1B / Slide 35 of 43
Working With Windows Forms


Operators (Contd.)
    •    Concatenation Operators: Concatenation Operators are used to join two
         expressions.
         • &
         • +




 ©NIIT                  Introduction to VB .NET        Lesson 1B / Slide 36 of 43
Working With Windows Forms


Control Flow Constructs
    •    You can control the sequence of execution of statements by using various
         control statements and loops.
    •    Decision Structures
         • If-then-Else
         • Select Case
    •    Loop Structures
         • While-End While
         • Do-Loop
         • For-Next




 ©NIIT                  Introduction to VB .NET           Lesson 1B / Slide 37 of 43
Working With Windows Forms




                  Demo
         Creating Windows Forms




 ©NIIT       Introduction to VB .NET   Lesson 1B / Slide 38 of 43
Working With Windows Forms


Problem Statement

    Create an application to accept a user name and a password through a startup
    screen. The application should check whether the login name is “sa” and the
    password is “callcenter”. The user should be provided with three logon attempts.
    After three unsuccessful logon attempts, application should display an error
    message. Also, the stratup screen should be closed.




 ©NIIT                   Introduction to VB .NET           Lesson 1B / Slide 39 of 43
Working With Windows Forms


Solution

         •   Create a new VB .NET Project
         •   Design a Windows Form
         •   Add code to validate the user input
         •   Execute the Application




 ©NIIT                  Introduction to VB .NET    Lesson 1B / Slide 40 of 43
Working With Windows Forms


Validating User Inputs
    •    There are two ways to prompt a user for entering data properly. They are:
         • Display an error message to a user using the MessageBox function
         • Use the ErrorProvider control




 ©NIIT                   Introduction to VB .NET          Lesson 1B / Slide 41 of 43
Working With Windows Forms


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.

 ©NIIT                   Introduction to VB .NET         Lesson 1B / Slide 42 of 43
Working With Windows Forms


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.




 ©NIIT                  Introduction to VB .NET          Lesson 1B / Slide 43 of 43

Mais conteúdo relacionado

Mais procurados

Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual BasicSangeetha Sg
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training Moutasm Tamimi
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedurepragya ratan
 
VB Multiple Forms
VB Multiple FormsVB Multiple Forms
VB Multiple Formsobrienduke
 
VB.Net-Controls and events
VB.Net-Controls and eventsVB.Net-Controls and events
VB.Net-Controls and eventsPrachi Sasankar
 
toolbox and its properties in the visual basic
toolbox and its properties in the visual basictoolbox and its properties in the visual basic
toolbox and its properties in the visual basicadarsh-kaul
 
Grasp patterns and its types
Grasp patterns and its typesGrasp patterns and its types
Grasp patterns and its typesSyed Hassan Ali
 
Primary Key & Foreign Key part10
Primary Key & Foreign Key part10Primary Key & Foreign Key part10
Primary Key & Foreign Key part10DrMohammed Qassim
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Salim M
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 
Adbms 16 object definition language
Adbms 16 object definition languageAdbms 16 object definition language
Adbms 16 object definition languageVaibhav Khanna
 

Mais procurados (20)

linked list
linked listlinked list
linked list
 
Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
ADO CONTROLS - Database usage
ADO CONTROLS - Database usageADO CONTROLS - Database usage
ADO CONTROLS - Database usage
 
Windows form application - C# Training
Windows form application - C# Training Windows form application - C# Training
Windows form application - C# Training
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
Introduction to UML
Introduction to UMLIntroduction to UML
Introduction to UML
 
Software Engineering by Pankaj Jalote
Software Engineering by Pankaj JaloteSoftware Engineering by Pankaj Jalote
Software Engineering by Pankaj Jalote
 
VB Multiple Forms
VB Multiple FormsVB Multiple Forms
VB Multiple Forms
 
VB.Net-Controls and events
VB.Net-Controls and eventsVB.Net-Controls and events
VB.Net-Controls and events
 
visual basic programming
visual basic programmingvisual basic programming
visual basic programming
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
toolbox and its properties in the visual basic
toolbox and its properties in the visual basictoolbox and its properties in the visual basic
toolbox and its properties in the visual basic
 
Grasp patterns and its types
Grasp patterns and its typesGrasp patterns and its types
Grasp patterns and its types
 
Primary Key & Foreign Key part10
Primary Key & Foreign Key part10Primary Key & Foreign Key part10
Primary Key & Foreign Key part10
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 
Rdbms
RdbmsRdbms
Rdbms
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 
INPUT BOX- VBA
INPUT BOX- VBAINPUT BOX- VBA
INPUT BOX- VBA
 
Adbms 16 object definition language
Adbms 16 object definition languageAdbms 16 object definition language
Adbms 16 object definition language
 

Destaque

SOAP--Simple Object Access Protocol
SOAP--Simple Object Access ProtocolSOAP--Simple Object Access Protocol
SOAP--Simple Object Access ProtocolMasud Rahman
 
Ch2(working with forms)
Ch2(working with forms)Ch2(working with forms)
Ch2(working with forms)Chhom Karath
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computersimran153
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.NetHitesh Santani
 

Destaque (6)

Vb tutorial
Vb tutorialVb tutorial
Vb tutorial
 
SOAP--Simple Object Access Protocol
SOAP--Simple Object Access ProtocolSOAP--Simple Object Access Protocol
SOAP--Simple Object Access Protocol
 
Vb.Net Web Forms
Vb.Net  Web FormsVb.Net  Web Forms
Vb.Net Web Forms
 
Ch2(working with forms)
Ch2(working with forms)Ch2(working with forms)
Ch2(working with forms)
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
 
Server Controls of ASP.Net
Server Controls of ASP.NetServer Controls of ASP.Net
Server Controls of ASP.Net
 

Semelhante a Vb.net session 02

Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09Niit Care
 
Vb.net session 03
Vb.net session 03Vb.net session 03
Vb.net session 03Niit Care
 
Vb.net session 10
Vb.net session 10Vb.net session 10
Vb.net session 10Niit Care
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01Niit Care
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15Niit Care
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0DivyaR219113
 
Object Oriented Programming I
Object Oriented Programming IObject Oriented Programming I
Object Oriented Programming Iraven_rainagi
 
Vb net xp_02
Vb net xp_02Vb net xp_02
Vb net xp_02Niit Care
 
Introduction to Visual Basic 6.0 Fundamentals
Introduction to Visual Basic 6.0 FundamentalsIntroduction to Visual Basic 6.0 Fundamentals
Introduction to Visual Basic 6.0 FundamentalsSanay Kumar
 
vb-160518151614.pdf
vb-160518151614.pdfvb-160518151614.pdf
vb-160518151614.pdfLimEchYrr
 
vb-160518151614.pptx
vb-160518151614.pptxvb-160518151614.pptx
vb-160518151614.pptxLimEchYrr
 

Semelhante a Vb.net session 02 (20)

Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
 
Vb.net session 03
Vb.net session 03Vb.net session 03
Vb.net session 03
 
01 gui 01
01 gui 0101 gui 01
01 gui 01
 
Vb.net session 10
Vb.net session 10Vb.net session 10
Vb.net session 10
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15
 
03 gui 04
03 gui 0403 gui 04
03 gui 04
 
Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0Introduction to Visual Basic 6.0
Introduction to Visual Basic 6.0
 
Ms visual-basic-6
Ms visual-basic-6Ms visual-basic-6
Ms visual-basic-6
 
Object Oriented Programming I
Object Oriented Programming IObject Oriented Programming I
Object Oriented Programming I
 
08 gui 11
08 gui 1108 gui 11
08 gui 11
 
Vb net xp_02
Vb net xp_02Vb net xp_02
Vb net xp_02
 
Introduction to Visual Basic 6.0 Fundamentals
Introduction to Visual Basic 6.0 FundamentalsIntroduction to Visual Basic 6.0 Fundamentals
Introduction to Visual Basic 6.0 Fundamentals
 
VISUAL PROGRAMMING
VISUAL PROGRAMMINGVISUAL PROGRAMMING
VISUAL PROGRAMMING
 
02 gui 02
02 gui 0202 gui 02
02 gui 02
 
vb.pptx
vb.pptxvb.pptx
vb.pptx
 
vb-160518151614.pdf
vb-160518151614.pdfvb-160518151614.pdf
vb-160518151614.pdf
 
vb-160518151614.pptx
vb-160518151614.pptxvb-160518151614.pptx
vb-160518151614.pptx
 
Vb 6ch123
Vb 6ch123Vb 6ch123
Vb 6ch123
 
Lec02
Lec02Lec02
Lec02
 

Mais de Niit Care (20)

Ajs 1 b
Ajs 1 bAjs 1 b
Ajs 1 b
 
Ajs 4 b
Ajs 4 bAjs 4 b
Ajs 4 b
 
Ajs 4 a
Ajs 4 aAjs 4 a
Ajs 4 a
 
Ajs 4 c
Ajs 4 cAjs 4 c
Ajs 4 c
 
Ajs 3 b
Ajs 3 bAjs 3 b
Ajs 3 b
 
Ajs 3 a
Ajs 3 aAjs 3 a
Ajs 3 a
 
Ajs 3 c
Ajs 3 cAjs 3 c
Ajs 3 c
 
Ajs 2 b
Ajs 2 bAjs 2 b
Ajs 2 b
 
Ajs 2 a
Ajs 2 aAjs 2 a
Ajs 2 a
 
Ajs 2 c
Ajs 2 cAjs 2 c
Ajs 2 c
 
Ajs 1 a
Ajs 1 aAjs 1 a
Ajs 1 a
 
Ajs 1 c
Ajs 1 cAjs 1 c
Ajs 1 c
 
Dacj 4 2-c
Dacj 4 2-cDacj 4 2-c
Dacj 4 2-c
 
Dacj 4 2-b
Dacj 4 2-bDacj 4 2-b
Dacj 4 2-b
 
Dacj 4 2-a
Dacj 4 2-aDacj 4 2-a
Dacj 4 2-a
 
Dacj 4 1-c
Dacj 4 1-cDacj 4 1-c
Dacj 4 1-c
 
Dacj 4 1-b
Dacj 4 1-bDacj 4 1-b
Dacj 4 1-b
 
Dacj 4 1-a
Dacj 4 1-aDacj 4 1-a
Dacj 4 1-a
 
Dacj 1-2 b
Dacj 1-2 bDacj 1-2 b
Dacj 1-2 b
 
Dacj 1-3 c
Dacj 1-3 cDacj 1-3 c
Dacj 1-3 c
 

Último

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Último (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Vb.net session 02

  • 1. 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 1. Which of the following information is not stored in Assemblies? a. Name of the assembly b. Version number of the assembly c. Security information d. Type-safety checks ©NIIT Introduction to VB .NET Lesson 1B / Slide 1 of 43
  • 2. Working With Windows Forms Pre-Assessment Questions (Contd.) 1. The Visual Studio .NET IDE provides three navigational features. Which of the following is not the navigational feature provided by .NET? a. Docking b. Tabbed Navigation c. Auto Hide d. Auto Visible 1. CLR enforces restrictions on managed code to provide Code Access Security. This is done through the use of objects. These objects are called a. GAC b. CTS c. CLS d. Permissions ©NIIT Introduction to VB .NET Lesson 1B / Slide 2 of 43
  • 3. Working With Windows Forms Pre-Assessment Questions (Contd.) 1. The capability of a derived class to hide the characteristics of the parent class is called a. Overriding b. Overloading c. Structured programming d. Inheritance ©NIIT Introduction to VB .NET Lesson 1B / Slide 3 of 43
  • 4. Working With Windows Forms Solutions to Pre-Assessment Questions 1. d. 2. d. 3. d 4. d. 5. a. ©NIIT Introduction to VB .NET Lesson 1B / Slide 4 of 43
  • 5. Working With Windows Forms 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 ©NIIT Introduction to VB .NET Lesson 1B / Slide 5 of 43
  • 6. Working With Windows Forms Getting Started With Windows Forms • A user interface is the means by which a user interacts with an application. • Two types of user interfaces are: • Character user interface (CUI): • Graphical user interface (GUI): • User interaction in a Windows-based application is accomplished through Windows Forms and controls. ©NIIT Introduction to VB .NET Lesson 1B / Slide 6 of 43
  • 7. Working With Windows Forms Introducing Windows Forms • A Windows Form • is a representation of any window displayed in an application. • is used to accept input from a user and display information. • is a class derived from Form class in System.Windows.Forms namespace. • can also be inherited from the existing forms in the project to change the existing behavior. • inherits many predefined properties, methods, and events associated with its base classes. ©NIIT Introduction to VB .NET Lesson 1B / Slide 7 of 43
  • 8. Working With Windows Forms Introducing Windows Forms (Contd.) The following figure shows a sample Windows Form for accepting login details from a user: 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. ©NIIT Introduction to VB .NET Lesson 1B / Slide 8 of 43
  • 9. Working With Windows Forms Windows Forms Properties • Windows Form properties are used to determine its appearance at run time. • The commonly used properties of a Windows Form are: • Name • BackColor • BackgroundImage • Font • Size • StartPosition • Text • WindowState ©NIIT Introduction to VB .NET Lesson 1B / Slide 9 of 43
  • 10. Working With Windows Forms Windows Forms Events • An event is generated when a user performs an action, such as clicking the mouse or pressing a key. • Each form and control has a predefined set of events associated with it. • The common events used in a Windows Form are: • Click • Closed • Deactivate • Load • MouseMove • MouseDown • MouseUp ©NIIT Introduction to VB .NET Lesson 1B / Slide 10 of 43
  • 11. Working With Windows Forms Windows Forms Events (Contd.) • Event handler is a special method that specifies the action to be performed on the occurrence of an event. • You can add the code for an event handler by using the Code Editor window as shown in the following figure: ©NIIT Introduction to VB .NET Lesson 1B / Slide 11 of 43
  • 12. Working With Windows Forms Windows Forms Events (Contd.) • The following example shows an event handler for the Load event of Form1: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’Code for initialization of form variables End Sub • In the given sample code: • sender provides a reference to the object that raised the event • e passes an object-specific input, such as the location of the mouse and the type of mouse event for the event being handled. ©NIIT Introduction to VB .NET Lesson 1B / Slide 12 of 43
  • 13. Working With Windows Forms Windows Forms Methods • Windows Form methods allow you to perform various tasks, such as opening, activating, and closing the form. • The commonly used methods are: • Show() • Activate() • Close() • SetDesktopLocation() ©NIIT Introduction to VB .NET Lesson 1B / Slide 13 of 43
  • 14. Working With Windows Forms 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. ©NIIT Introduction to VB .NET Lesson 1B / Slide 14 of 43
  • 15. Working With Windows Forms Form Controls (Contd.) The following figure shows some controls: TextBox Control- Multiline property set Label Control TextBox Control ListBox Control GroupBox Control CheckBox Control Button Control StatusBar Control ©NIIT Introduction to VB .NET Lesson 1B / Slide 15 of 43
  • 16. Working With Windows Forms The TextBox Control • The TextBox control is used to display text to a user or accept input from a user. • By default, you can enter a maximum of 2048 characters in a TextBox control. • The commonly used properties of the TextBox control are: • Text • MultiLine • PasswordChar ©NIIT Introduction to VB .NET Lesson 1B / Slide 16 of 43
  • 17. Working With Windows Forms The Label Control • The Label control • is used to display the text that cannot be edited by the user directly. • is used for providing information or description of another control on the Windows Form. • The commonly used properties of the Label control are: • Text • AutoSize ©NIIT Introduction to VB .NET Lesson 1B / Slide 17 of 43
  • 18. Working With Windows Forms The LinkLabel Control • The LinkLabel control is used to display the text as a link to another form or Web site. • The LinkLabel control has all properties of a Label control. • The commonly used additional properties are: • LinkColor • ActiveLinkColor • DisabledLinkColor • LinkVisited ©NIIT Introduction to VB .NET Lesson 1B / Slide 18 of 43
  • 19. Working With Windows Forms The ListBox Control • The ListBox control is used to display a list of items to a user. • A user can select an item from the list. • You can add items to a ListBox control by using the properties window. • The commonly used properties of the ListBox control are: • SelectionMode • Sorted • SelectedIndex • SelectedItem ©NIIT Introduction to VB .NET Lesson 1B / Slide 19 of 43
  • 20. Working With Windows Forms The ComboBox Control • The ComboBox control • is used to display a drop-down list of items. • is a combination of a text box in which a user enters an item and a drop- down list from which a user selects an item. • can be populated using the Properties window. • The commonly used properties of the ComboBox control are: • Text • Sorted • SelectedIndex • SelectedItem ©NIIT Introduction to VB .NET Lesson 1B / Slide 20 of 43
  • 21. Working With Windows Forms The CheckBox Control • The CheckBox control is used to set Yes/No or True/false options. • The commonly used properties of the CheckBox control are: • Text • Checked ©NIIT Introduction to VB .NET Lesson 1B / Slide 21 of 43
  • 22. Working With Windows Forms The RadioButton Control • The RadioButton control is used to provide a set of mutually exclusive options to the user. • Only one radio button can be selected in a group. • The commonly used properties of the RadioButton control are: • Text • Checked ©NIIT Introduction to VB .NET Lesson 1B / Slide 22 of 43
  • 23. Working With Windows Forms The GroupBox Control • The GroupBox control • is used to group related controls together. • facilitates the group of controls to be easily moved together at design time. • You can specify the caption to be displayed for a GroupBox control by setting the Text property at runtime as follows: GroupBox1.Text = “Select Gender” ©NIIT Introduction to VB .NET Lesson 1B / Slide 23 of 43
  • 24. Working With Windows Forms The Button Control • The Button control is used to perform an action when a user clicks it. • The Button control has the Text property, which is used to display text on a button. • You can also set the Text property at run time, as shown below: GroupBox1.Text = “Select Gender” ©NIIT Introduction to VB .NET Lesson 1B / Slide 24 of 43
  • 25. Working With Windows Forms The StatusBar Control • The StatusBar control is used to display the status information at the bottom of the form. • The commonly used properties of the StatusBar control are: • ShowPanels • Text • You can display different text in different panels of a StatusBar control by following steps: • set the ShowPanels property to True. • add the text for each panel of the StatusBar control by using the Panels collection. ©NIIT Introduction to VB .NET Lesson 1B / Slide 25 of 43
  • 26. Working With Windows Forms Form Controls (Contd.) • The events associated with various controls can be categorized as follows: • Keyboard events • KeyDown • KeyUp • KeyPress • Mouse events • MouseDown • MouseUp • MouseMove • Control-specific events • Resize • VisibleChanged ©NIIT Introduction to VB .NET Lesson 1B / Slide 26 of 43
  • 27. Working With Windows Forms Dynamically Loading Controls in Windows Forms • The loading of controls at runtime is called as dynamic loading of controls. • Every control is a class derived from the System.Windows.Forms.Control class. • Whenever you load a control from the toolbox in the form, an object of the class is created. • Example: To dynamically load a text box, you need to specify the following code in the Form1_Load event of the Windows Form: Dim Txt1 As TextBox = New TextBox() Form1.Controls.Add(Txt1) The text box, Txt1 will be shown in the upper-left corner of the Form1. ©NIIT Introduction to VB .NET Lesson 1B / Slide 27 of 43
  • 28. Working With Windows Forms Introducing VB .NET Language Fundamentals • VB .NET provides a number of language features. The fundamental features are: • Data types • Variables • Arrays • Operators • Control Flow Constructs ©NIIT Introduction to VB .NET Lesson 1B / Slide 28 of 43
  • 29. Working With Windows Forms     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
  • 30. 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 ©NIIT Introduction to VB .NET Lesson 1B / Slide 30 of 43
  • 31. Working With Windows Forms 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. ©NIIT Introduction to VB .NET Lesson 1B/ Slide 31 of 43
  • 32. Working With Windows Forms 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. ©NIIT Introduction to VB .NET Lesson 1B/ Slide 32 of 43
  • 33. Working With Windows Forms 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 ©NIIT Introduction to VB .NET Lesson 1B / Slide 33 of 43
  • 34. Working With Windows Forms Operators (Contd.) • Comparison Operators: Comparison operators are used to compare two values and perform an action based on the result of the comparison. • < • > • <= • >= • = • <> ©NIIT Introduction to VB .NET Lesson 1B / Slide 34 of 43
  • 35. Working With Windows Forms Operators (Contd.) • Logical operators: Logical operators are used to evaluate expressions and return a Boolean value. • And • Not • Or • Xor • OrElse • AndAlso ©NIIT Introduction to VB .NET Lesson 1B / Slide 35 of 43
  • 36. Working With Windows Forms Operators (Contd.) • Concatenation Operators: Concatenation Operators are used to join two expressions. • & • + ©NIIT Introduction to VB .NET Lesson 1B / Slide 36 of 43
  • 37. Working With Windows Forms Control Flow Constructs • You can control the sequence of execution of statements by using various control statements and loops. • Decision Structures • If-then-Else • Select Case • Loop Structures • While-End While • Do-Loop • For-Next ©NIIT Introduction to VB .NET Lesson 1B / Slide 37 of 43
  • 38. Working With Windows Forms Demo Creating Windows Forms ©NIIT Introduction to VB .NET Lesson 1B / Slide 38 of 43
  • 39. Working With Windows Forms Problem Statement Create an application to accept a user name and a password through a startup screen. The application should check whether the login name is “sa” and the password is “callcenter”. The user should be provided with three logon attempts. After three unsuccessful logon attempts, application should display an error message. Also, the stratup screen should be closed. ©NIIT Introduction to VB .NET Lesson 1B / Slide 39 of 43
  • 40. Working With Windows Forms Solution • Create a new VB .NET Project • Design a Windows Form • Add code to validate the user input • Execute the Application ©NIIT Introduction to VB .NET Lesson 1B / Slide 40 of 43
  • 41. Working With Windows Forms Validating User Inputs • There are two ways to prompt a user for entering data properly. They are: • Display an error message to a user using the MessageBox function • Use the ErrorProvider control ©NIIT Introduction to VB .NET Lesson 1B / Slide 41 of 43
  • 42. Working With Windows Forms 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. ©NIIT Introduction to VB .NET Lesson 1B / Slide 42 of 43
  • 43. Working With Windows Forms 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. ©NIIT Introduction to VB .NET Lesson 1B / Slide 43 of 43