Creating the User Interface - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Creating the User Interface

Description:

It provides a framework that you can use throughout your application to give a ... Deactivate. QueryUnload (you need to know how the user is closing the form) ... – PowerPoint PPT presentation

Number of Views:16
Avg rating:3.0/5.0
Slides: 18
Provided by: abc105
Category:

less

Transcript and Presenter's Notes

Title: Creating the User Interface


1
Chapter 1
  • Creating the User Interface
  • Lesson 2 Overview of User Interface Elements

2
Learning Objectives
  • Discuss the two types of Visual Basic
    controls.
  • Add controls to a form.
  • Explain control arrays.
  • Set control and form properties.
  • Assign code to event properties.
  • Explain control and form collections.

3
What is a Form
  • It provides a framework that you can use
    throughout your application to give a consistent
    look and feel to your user interface.

4
What is a control?
  • Controls are objects that you add to a form.
    Each has it own set of properties, methods, and
    events that provide a specific capability to your
    application.

5
ActiveX controls
  • Standard controls (command button, text box)
  • Custom controls you can add to your project.
    (Microsoft Windows Common Controls 6.0, Microsoft
    Masked Edit Control 6.0)
  • Some of commonly used ActiveX control such as
    TreeView, ListView, ImageList, ToolBar,
    StatusBar)

6
Adding ActiveX Controls
  • To add an ActiveX control to the Components
    dialog box
  • To add an ActiveX control to the Toolbox

7
Control Arrays
  • You reference individual elements in the control
    array by an index.
  • Example menu control, option button groupings.

8
Coding a Control Array
  • controlname(index).property expression
  • Private Sub chkPreferences_Click(Index As
    Integer)
  • If chkPreferences(Index).Value vbChecked
    Then
  • Select Case Index
  • Case 0
  • MsgBox "You will be notified by
    mail"
  • Case 1
  • MsgBox "You will be notified by
    phone"
  • Case 2
  • MsgBox "You will not be notified"
  • End Select
  • End If
  • End Sub

9
Creating Controls at Run Time
  • Private Sub Form_Load()
  • Dim ctlWName As Control
  • Set ctlWName frmName.Controls.Add("VB.TextBox",
    _
  • "txtControlName", frmName)
  • With ctlWName
  • .Visible True
  • .Top 200
  • .Left 200
  • .Width 2000
  • .Height 200
  • .Font.Size 10
  • End With
  • End Sub

10
  • To set a control property at design time
  • To set a property for multiple controls at design
    time
  • Setting properties at run time

11
What is an event
  • An event is a signal to your application that
    some kind of system or user activity has taken
    place.
  • An event procedure is simply a procedure that is
    executed in response to a particular event
    (Click).
  • Visual Basic events are triggered, or fired, by
    the system or by user action.
  • Timer event in a Timer control (system event)
  • Click event (by user action)

12
Standard Form Events
  • Initialise (Before the form is loaded or
    displayed)
  • Load (Form1.show or Load Form1)
  • Activate (when focus is changing within the same
    application)
  • Deactivate
  • QueryUnload (you need to know how the user is
    closing the form)
  • Unload (include form-level validation code needed
    for closing the form )
  • Terminate (are removed from memory)

13
  • Private Sub Exit_Click()
  • End
  • End Sub
  • Private Sub Form_Activate()
  • MsgBox "Active stage ..."
  • End Sub
  • Private Sub Form_Initialize()
  • MsgBox "Initialise stage ...."
  • End Sub
  • Private Sub Form_Load()
  • MsgBox "Loading stage ..."
  • txtData.Font.Bold True
  • txtData.Text "Hello World"
  • End Sub
  • Private Sub Form_QueryUnload(Cancel As Integer,
    UnloadMode As Integer)
  • If UnloadMe ltgt vbFormCode Then
  • MsgBox "Use the Exit button to close the form"
  • Cancel True
  • End If

14
What is a collection?
  • A collection is a group of related objects.
  • Examples
  • A project can have a collection of forms.
  • A form can have a collection of controls.

15
Creating a Collection
  • Private Sub cmdCollection_Click()
  • Dim col As New Collection
  • Dim var As Variant
  • col.Add "First Value"
  • col.Add "Second Value"
  • col.Add "Third Value"
  • For Each var In col
  • Debug.Print var
  • Next var
  • End Sub

16
Practice Using the Collection Objects Add Method
  • Private colDroppedControls As New Collection
  • Private Sub cmdListCollection_Click()
  • Dim vnt As Variant
  • For Each vnt In colDroppedControls
  • Debug.Print vnt
  • Next vnt
  • End Sub

17
  • Private Sub List1_DragDrop(Source As VB.Control,
    _
  • X As Single, Y As Single)
  • Dim vnt As Variant
  • For Each vnt In colDroppedControls
  • If vnt Is Source Then
  • Beep
  • Exit Sub
  • End If
  • Next
  • colDroppedControls.Add Source
  • List1.AddItem SourceName
  • End Sub
Write a Comment
User Comments (0)
About PowerShow.com