Visual Basic Programming 2 - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Visual Basic Programming 2

Description:

Putting values into List - AddItem Method. Normally each new item is ... List has index value 0. An additonal integer parameter allows you to insert the ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 21
Provided by: PeterW172
Category:

less

Transcript and Presenter's Notes

Title: Visual Basic Programming 2


1
Visual Basic Programming 2
  • Lecture 1
  • Review of typical Control - List Box
  • Review of Methods, Properties, Events
  • Introduce Combo Box Control
  • Properties, Methods and Events
  • Comparison with List Box
  • Lecture 2
  • Drop-Down Menus
  • Producing and using drop-down menus

2
List Box Control
Select from given options.
3
List box methods - AddItem
  • Putting values into List - AddItem Method
  • Normally each new item is appended to the List
  • First item in List has index value 0. An
    additonal integer parameter allows you to insert
    the new value into the middle of the list - see
    below

Private Sub Form_Load() lstNames.AddItem
"Anna" lstNames.AddItem "Craig"
lstNames.AddItem "Darren" lstNames.AddItem
"Mel" lstNames.AddItem "Nick"
lstNames.AddItem "Claire", 1 End Sub
4
List box Methods - RemoveItem Clear
  • RemoveItem deletes a selected entry from List
  • e.g. To remove the fifth entry (index value
    4!!) List1.RemoveItem 4
  • This removes Nick
  • Clear deletes all List entries
  • e.g. List1.Clear

5
List Box - Selected Properties
  • Sorted When TRUE, this automatically sorts
    entries into alphabetical order.
  • Text Value of selected item in List
  • ListCount Total no. of items in List
  • e.g. NoOfItems List1.ListCount
  • List(n) Contents of selected item in List
  • e.g. Value List1.List(3) Element no.3 in
    list1
  • ListIndex Index no. of selected item
  • e.g. ElementNo List1.ListIndex
  • N.B. The last 3 Properties are available at
    Run-Time only

6
List box - More properties
  • Columns(n) Select multiple column display
  • MultiSelect Default (0) allows only 1 item to
    be selected If set to 1 allows one or more
    items selected
  • Selected(n) Array showing which items are
    selected.
  • e.g. If List1.Selected(3).....

7
Combo Box Control
Similar to List Box, but with its own text entry
area.
You may select one of the options or enter
another value.
8
Combo Box - Selected Properties
  • Combo box shares many properties with List box,
    including
  • Sorted
  • Text
  • List(n)
  • ListIndex
  • ListCount
  • Combo box may not use multiple columns
  • i.e. Columns(n) not allowed.
  • Combo Box may not select more than one option at
    a time
  • i.e. MultiSelect Selected(n) not allowed

9
Events for List box Combo box
  • List and Combo both respond to the following
    events
  • Click, DblClick, DragDrop, DragOver, GotFocus,
    LostFocus, KeyDown, KeyUp and KeyPress
  • List box (but not Combo box) responds to these
    events
  • MouseDown, MouseUp and MouseMove
  • Combo box (but not List box) responds to these
    events
  • Change (when user types in edit area)
  • DropDown (when arrow to right of edit area is
    clicked to drop down the list portion)

10
Comparing List box Combo box
Combo box
List box
  • Occupies only one line on form when not in use.
    Drop-down list appears when in use.
  • Can select from entries shown, or type in
    another value
  • Can select only one entry
  • Can display only one column
  • Occupies several lines on form at all
    times
  • Can select only from entries shown
  • Can select several items
  • Can display list in multiple columns

11
A Typical Drop-down menu
Menu bar
Shortcuts
Checked option
Cascading Menus
Separator bar
Disabled Options
12
The Menu Design Window
This code gives Label1 blue text when Blue
Text option is selected
13
Creating the first option
Caption, to go on menu
Internal name for option (used in programming -
choose a meaningful name)
Update the Index value (optional)
Caption value echoed here
14
Adding further options
Press Next key to create another option
Use left/right arrow keys to create sub-menus
Select shortcut letter by preceding it with .
Option is enabled (can be selected) and
visible (default values)
15
Changing the order of the Options
Select the option to be moved...
...then move it with the up/down arrow keys
16
Inserting another option into the menu
e.g. Select About option, then press Insert key.
before...
after...
17
Adding shortcuts
Shortcut keys
Shortcut key selection
18
Adding a Separator bar to your menu
Separator bar
Caption -
Choose any Name
19
Using the checked option
Checked option in use.
(N.B. Other options can also be
disabled if required.)
20
Setting the Checked Enable options in code
Private Sub mnuTransparent_Click() If
mnuTransparent.Checked True Then
lblBlue.BackStyle 1 mnuTransparent.Check
ed False mnuYellow.Checked True
mnuGrey.Checked True Else
lblBlue.BackStyle 0 mnuTransparent.Check
ed True mnuYellow.Checked False
mnuGrey.Checked False End If End Sub
Write a Comment
User Comments (0)
About PowerShow.com