SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
pragya ratan
 
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
Salim M
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
pbarasia
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
bloodyedge03
 

What's hot (20)

C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
VB.NET:An introduction to Namespaces in .NET framework
VB.NET:An introduction to  Namespaces in .NET frameworkVB.NET:An introduction to  Namespaces in .NET framework
VB.NET:An introduction to Namespaces in .NET framework
 
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
 
Sdi & mdi
Sdi & mdiSdi & mdi
Sdi & mdi
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
Common dialog control
Common dialog controlCommon dialog control
Common dialog control
 
Buttons In .net Visual Basic
Buttons In .net Visual BasicButtons In .net Visual Basic
Buttons In .net Visual Basic
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
Vb basics
Vb basicsVb basics
Vb basics
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
 
Active x control
Active x controlActive x control
Active x control
 
Visual basic
Visual basicVisual basic
Visual basic
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
4.C#
4.C#4.C#
4.C#
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Event driven theory
Event driven theoryEvent driven theory
Event driven theory
 
Vb introduction.
Vb introduction.Vb introduction.
Vb introduction.
 
visual basic v6 introduction
visual basic v6 introductionvisual basic v6 introduction
visual basic v6 introduction
 
Graphical User Interface (GUI)
Graphical User Interface (GUI)Graphical User Interface (GUI)
Graphical User Interface (GUI)
 

Viewers also liked

Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
simran153
 

Viewers also liked (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
 

Similar to Vb.net session 02

Vb.net session 09
Vb.net session 09Vb.net session 09
Vb.net session 09
Niit Care
 
Vb.net session 03
Vb.net session 03Vb.net session 03
Vb.net session 03
Niit Care
 
Vb.net session 10
Vb.net session 10Vb.net session 10
Vb.net session 10
Niit Care
 
Vb.net session 01
Vb.net session 01Vb.net session 01
Vb.net session 01
Niit Care
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15
Niit Care
 
Vb net xp_02
Vb net xp_02Vb net xp_02
Vb net xp_02
Niit Care
 

Similar to 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
 

More from 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
 

Recently uploaded

Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 

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