Programming for GIS - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Programming for GIS

Description:

Found in the Dialogs section of the Toolbox ... End Sub. Chapter 9 - VB 2005 by Schneider. 17. Four ... Private Sub Tally(...) Handles chkDrugs.CheckedChanged, ... – PowerPoint PPT presentation

Number of Views:60
Avg rating:3.0/5.0
Slides: 37
Provided by: cwy72
Category:

less

Transcript and Presenter's Notes

Title: Programming for GIS


1
Programming for GIS
  • Keith T. Weber, GISP
  • GIS Director, ISU

2
Additional Controls and Objects
  • List Boxes, Combo Boxes, and the File-Opening
    Control
  • Four Elementary Controls
  • MDI

3
List Boxes, Combo Boxes, and the OpenFile Control
  • The List Box Control
  • The Combo Box Control
  • The OpenFileDialog Control

4
The List Box Control
  • Items can be placed into the list at design time
    or run time
  • The Sorted property causes items in the list to
    be sorted automatically
  • If the Sorted property is set to True, then the
    following will place an item into the list in
    order and assign the index of its position to
    num
  • num lstBox.Items.Add(str)

5
Useful Properties of the List Box
  • For the total number of items in a list box
  • lstBox.Items.Count
  • Note Each item in lstBox is identified by an
    index number from 0 to lstBox.Items.Count - 1
  • For the index number of the currently highlighted
    item
  • lstBox.SelectedIndex

6
More List Box Properties
  • lstBox.Items() is the list of items in the list
    box.
  • The value of the item with an index of n is
  • lstBox.Items(n)
  • The data type of the elements in the
    lstBox.Items() array is Object. To put the first
    element of lstBox.Items in a text box
  • txtBox.Text CStr(lstBox.Items(0))

7
Currently Highlighted Item in a List Boxes
  • The currently highlighted item can be obtained
    as
  • lstBox.Items(lstBox.SelectedIndex)
  • Or
  • lstBox.Text

8
Removing Items from a List Box
  • To delete an item at a given location
  • lstBox.Items.RemoveAt(n)
  • To delete the first occurrence of an item
  • lstBox.Items.Remove(str)
  • To remove everything from a list box
  • lstBox.Items.Clear()

9
The Combo Box Control
  • A list box combined with a text box
  • The user has the option of selecting from a list
    or typing in something
  • Essentially same properties, events, and methods
    as list box

10
The Combo Box Control
  • Three types of combo boxes in the DropDownStyle
    property

DropDown (and DropDownList) combo box
Simple combo box
11
The OpenFileDialog Control
  • Implements the standard File Open dialog box
  • Found in the Dialogs section of the Toolbox
  • Note When you place the control on the form, it
    will not be visible. The icon and default name
    will appear in the pane below the Main area.

12
An Open File Dialog Box
13
The Filter Property
  • Determines what appears in the Files of type
    combo box, and what types of files will be
    displayed. The setting has the general form
  • text for combo box.ext
  • Example Text Files (.TXT).TXT

14
Using the OpenFileDialog control
  • To display the control
  • OpenFileDialog1.ShowDialog()
  • After the Open button has been pressed, the file
    name selected and its complete filespec will be
    contained in the property
  • OpenFileDialog1.FileName

15
An Example
  • Select a text file and display its contents.
  • Note The Filter property of OpenFileDialog1 is
    set to
  • Text Files (.TXT).TXT

16
Example Code
  • Private Sub btnSelect_Click(...) Handles _
  • btnSelect.Click
  • Dim textFile As String
  • OpenFileDialog1.ShowDialog()
  • textFile OpenFileDialog1.FileName
  • Dim sr As IO.StreamReader _
  • IO.File.OpenText(textFile)
  • Do While sr.Peek ltgt -1
  • lstOutput.Items.Add(sr.ReadLine)
  • Loop
  • sr.Close()
  • End Sub

17
Four Elementary Controls
  • The Group Box Control
  • The Check Box Control
  • The Radio Button Control
  • The Timer Control

18
The Group Box Control
  • Group boxes are passive objects used to group
    other objects together
  • When you drag a group box, the attached controls
    follow as a unit
  • To attach a control to a group box, create the
    group box, then drag the control you want to
    attach into the group box

19
Group Box Example
Text property of the group box
Three attached controls Button1 Button2 Button3
20
The Check Box Control
  • Consists of a small square and a caption
  • Presents the user with a Yes/No choice
  • During run time, clicking on the check box
    toggles the appearance of a check mark.
  • Checked property is True when the check box is
    checked and False when it is not
  • CheckedChanged event is triggered when the user
    clicks on the check box

21
Example 2 Form
22
Example 2 Code
  • Private Sub Tally(...) Handles chkDrugs.CheckedCha
    nged, _
  • chkDental.CheckedChanged, chkVision.CheckedCha
    nged, _
  • chkMedical.CheckChanged
  • Dim sum As Double 0
  • If chkDrugs.Checked Then
  • sum 12.51
  • End If
  • If chkDental.Checked Then
  • sum 9.68
  • End If
  • If chkVision.Checked Then
  • sum 1.5
  • End If
  • If chkMedical.Checked Then
  • sum 25.25
  • End If
  • txtTotal.Text FormatCurrency(sum)
  • End Sub

23
Example 2 Output
24
The Radio Button Control
  • Consists of a small circle with a caption (that
    is set by the Text property)
  • Normally several radio buttons are attached to a
    group box
  • Gives the user a single choice from several
    options
  • Clicking on one radio button removes the
    selection from another

25
Radio Button Properties
  • To determine if the button is on or off
  • radButton.Checked
  • has value True if button in on.
  • To turn a radio button on
  • radButton.Checked True

26
Example 3 Form
radCandidate1
radCandidate2
txtVote
27
Example 3 Code
  • Private Sub btnVote_Click(...) Handles
    btnVote.Click
  • If radCandidate1.Checked Then
  • txtVote.Text "You voted for Kennedy."
  • ElseIf radCandidate2.Checked Then
  • txtVote.Text "You voted for Nixon."
  • Else
  • txtVote.Text "You voted for neither."
  • End If
  • End Sub

28
Example 3 Output
29
The Timer Control
  • Invisible during run time
  • Triggers an event after a specified period of
    time
  • The Interval property specifies the time period
    measured in milliseconds
  • To begin timing, set the Enabled property to True
  • To stop timing, set the Enabled property to False
  • The event triggered each time Timer1.Interval
    elapses is called Timer1.Tick.

30
Multiple Forms
  • Visual Basic programs can contain more than one
    form
  • To add the new form, select Add Windows Form from
    the Project menu, to invoke the Add New Items
    dialog box.

31
Add New Items dialog box
32
Add New Items dialog box
  • Select Windows Form from the Installed Templates
    pane.
  • Optionally type in a name.
  • Press the Add button.

33
Solution Explorer
  • Both forms will be accessible through Solution
    Explorer.

34
Variables and Multiple Forms
  • Variables declared in the declarations section of
    a form with Public, instead of Dim, will be
    available to all forms in the program.
  • When a Public variable is used in another form,
    it is referred to by an expression such as
  • secondForm.variableName

35
Key Concepts
  • There are numerous controls that can be placed on
    your GUI. Each has specific purposes. You
    should understand how to choose the best control
    for your needs.

36
Questions?
Write a Comment
User Comments (0)
About PowerShow.com