Escolar Documentos
Profissional Documentos
Cultura Documentos
VB.NET
VB.NET’s’s Form
Visual Basic.NET
by Has Bunton
1
Form and Window
The term form and window describe
the same entity.
The window is what the user sees when
the application is running.
A form or Window form is the same
entity at design time
by Has Bunton 2
Properties of the Form Control
Accept Button/Cancel Button: These
properties specify button to be automatically
activated when user presses Enter or Esc key
AutoScale: Automatically scale the height of
the control to be placed on the form to fit
the height of text.
AutoScroll*: Automatically
attaches scroll bars to the
form when it’s resized to
the point that not all its
controls are visible.
Etc.
by Has Bunton 3
Designing Functional Form
Data entry form is one of the interfaces
users work with most of the time and they
work mostly with keyboard
In developing data entry form you must
consider the following:
1. User needs
2. Make prototype and ask users to test-drive it
3. Listen to user’s objections and use them to
refine your application’s user interface
4. Don’t defense your design
by Has Bunton 4
The Contacts Project
Objective: Demonstrate a few
techniques for designing easy to use
forms
Design:
by Has Bunton 5
Coding - The Contacts Project (1)
1. Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
' F10 displays the number of contacts
2. If e.KeyCode = Keys.F10 Then
3. MsgBox("There are a number of contacts“)
e.Handled = True
4. End If
' ALT+ takes you to next contact, ALT- takes you to previous contact
5. If e.KeyCode = Keys.Subtract And e.Modifiers = Keys.Alt Then
6. MsgBox(“Move previous“)
7. End If
8. If e.KeyCode = Keys.Add And e.Modifiers = Keys.Alt Then
9. MsgBox(“Move next“)
10. End If
11. End Sub
by Has Bunton 6
The Form’s Events
Activate and Deactivate: Happen when
you click on another form or when you
press Alt + Tab
Resize: Fired every time the user
resizes the form using mouse
Etc.
by Has Bunton 7
Designing Menus
Start by double clicking the MainMenu icon
on the toolbox
The MenuItem represents a menu command,
at any level, with its own
property.
To create a separator bar,
use a dash (-)
To Insert an item, right-
click, select Insert New
by Has Bunton 8
MenuItem Object’s Properties
Check
DefaultItem
Enabled
Visible
Etc.
by Has Bunton 9
Manipulating Menus at Runtime
Dynamic menus change at runtime to display
more or fewer commands.
by Has Bunton 10
Creating Short and Long Menus
Start a new project and create menu with
the structure as above.
Write the following code
1. Protected Sub MenuSize_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MenuSize.Click
2. If MenuSize.Text = ">>" Then
3. MenuSize.Text = "<<"
4. Else
5. MenuSize.Text = ">>"
6. End If
by Has Bunton 11
Creating Context Menu
To create a context menu, place a
CentextMenu Control on your form. Except
the first command, which is the context
menu’s name, it is identical to the
MainMenu, but it won’t be displayed there
at runtime
To associate a context menu with a
control, set the control context menu
property to the name of the corresponding
context menu.
by Has Bunton 12
Adding Controls at Runtime*
To add controls at runtime first
initialize the control, set it
properties, and finally call Add
method od the control collection.
Example:
1. Dim Bttn as New System.Winforms.Button
2. Bttn.text = “New Button”
3. Bttn.Left = 100
4. Bttn.Top = 60
5. Bttn.Width = 80
6. Me.Controls.add (bttn)
by Has Bunton 13
The Dynamic Form Project
This project allows user to specify at
runtime the number of data points
they wish to enter, and the number of
textboxes on the form changes.
The control at the top
of the form is the
NumericUpDown
control
by Has Bunton 14
Coding The Dynamic Form Project (1)
by Has Bunton 15
Coding The Dynamic Form Project (2)
by Has Bunton 16
Coding The Dynamic Form Project (3)
by Has Bunton 17
Reading the Control on the Form (4)
by Has Bunton 18
Creating Event Handlers at Runtime
Create a subroutine that accepts two
arguments, the sender and e. The
name of argument can be anything
Enter the code for the event
Connect it to an event of a specific
control using the following syntax
1. AddHandler Control.Event, New System.EventHandler(AddressOf SubName)
by Has Bunton 19
Event Handlers Added at Runtime