Controls I - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Controls I

Description:

Controls I. Hello World Program. Make a TextBox to display 'Hello, world! ... Sonata Tico Avante (hint) Make two frames having 3 option boxes each. ListBox ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 21
Provided by: kowonDo
Category:
Tags: controls | sonata

less

Transcript and Presenter's Notes

Title: Controls I


1
Controls I
2
Hello World Program
  • Make a TextBox to display Hello, world! when OK
    button is clicked.

3
Hello World Program(cont.)
  • Enter the following code for command1_click()
  • Text1.Text Hello, world!

4
Exercise
  • Make a clear button to clean the TextBox.

5
Using File System Objects
  • Browser Program
  • A program that can display a picture file in the
    image object.
  • A file can be selected by using
  • DriverListBox,
  • DirListBox, and
  • FileListBox

6
The Format of Graphic Data
  • bitmap .bmp
  • Windows meta file .wmf
  • icon .ico
  • cursor .cur
  • JPEG .jpg
  • GIF .gif

7
Making a file selection object
  • Make DriverListBox, DirListBox, and FileListBox,
    (see the next slide) and enter the following code
    for each objects
  • Private Sub Drive1_Change()
  • Dir1.Path Drive1.Drive set the drive of
    Dir1 to Drive1
  • End Sub
  • Private Sub Dir1_Change()
  • File1.Path Dir1.Path set the directory of
    File1 to Dir1
  • End Sub
  • Private Sub File1_Click()
  • SelectedFile File1.Path "\"
    File1.FileName
  • Image1.Picture LoadPicture(SelectedFile)
  • End Sub

8
Making a file selection object(cont.)
DriverListBox
DirListBox
FileListBox Pattern .bmp
Image Stretch True BorderStyle 1-????
9
Jargon
  • Controls
  • Tools in the toolbox to make objects on the forms
    of VB
  • Objects
  • User Interface elements on the VB forms
  • Have inherent functionality like OOP
  • Attributes
  • Describes the property of each object
  • Way to set attribute value
  • object.property value

10
Jargon(cont.)
  • Event procedures
  • Procedures that are executed when some events
    related to the object occur
  • ex) clicking of end button ? stopping the
    program
  • Methods
  • specific statements for a specific object
  • format object.method input_value
  • ex) List1.Additem Check

11
Check box
  • Make a textbox with text1.text Division of
    Internet Engineering
  • Make 2 checkBoxes
  • And change the name of each checkBoxes
  • from check1 to chk??
  • And check2 to chk????
  • add the code for each event procedure as in p66
    67

12
Option Buttons
  • Can be used to select one among several choices
  • Value attribute
  • If the option button is selected, value TRUE
  • You can group them using Frames
  • Exercise
  • Make 3 option buttons and 1 textBox like in p 69
  • Use copy and paste function to make the 3 buttons
  • Enter the code in p 69

13
Options buttons (cont)
  • Frame can be used to group option buttons
  • Exercise
  • Make a form like fig 2.8 in p 69
  • We should make the frame first
  • Or we can use cut paste function
  • Enter the code in p 70

14
Exercise
  • Make a form that displays 2 questions asking
  • What is your hobby?
  • ? Reading ? Dancing ? Music listening
  • What is your favorite car?
  • ? Sonata ? Tico ? Avante
  • (hint) Make two frames having 3 option boxes each

15
ListBox
  • You can show a list of items by using a list box
  • Important attributes
  • ListIndex the index of user selected item
  • List the data array for the list box
  • Important method
  • AddItem adds a new item in the list box

16
Exercise
  • Make a form as in p 74
  • Use
  • Label
  • Listbox
  • commandButton
  • Add the event procedures as in p 75
  • Hint
  • Use list attribute for the list values
  • Use ctrlenter for continuous entering
  • Use just enter to finish entering

17
addItem in the ListBox
  • AddItem method can be used to enter initial
    values of the listbox
  • Format list.AddItem item
  • Exercise
  • Make 4 labels and 1 listBox as in p 75, 76
  • Use AddItem method to enter new values as in the
    middle of p 77
  • For list1_click procedure, enter the code in p 76

18
Exercise
  • Make 1 textbox, 1 listbox, and 3 buttons add,
    delete, end
  • If add button is pressed, enlist the text in
    the textbox into the listbox
  • If delete button is pressed, drop the item form
    the listbox
  • Hint use the following attributes and method
  • AddItem Text1.Text
  • List1.RemoveItem (List1.ListIndex)

19
Combo Box
  • Similar to ListBox but only one item can be seen
  • Initial items can be given using the list
    attribute
  • Enter the following as the list value Kim, Tom,
    Judy, Bob
  • You can insert an item in the combo box
  • After inserting an item, press enter key
  • Exercise
  • Make a form like p 81 (see the table in p 80 for
    values of attributes)
  • Enter the code in p 81

20
Exercise
  • Make a form that has one label, and two combo
    boxes, and one end button
  • For the first combo box, enter the list as
    choices
  • Tom, Bob, Jim, Tony, Brown
  • For the second combo box, enter the list as
    choices
  • Mary, Nancy, Kim, Betty, Lee
  • If male or female is selected, display one of the
    following message in the label depending on
    gender
  • Mr.XX is selected! where XX is one in the list
  • Ms.XX is selected! where XX is one in the list
Write a Comment
User Comments (0)
About PowerShow.com