Académique Documents
Professionnel Documents
Culture Documents
Objectives (1 of 2)
Chapter 7
McGraw-Hill
7-2
Copyr ight 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Objectives (2 of 2)
7-3
7-4
7-6
7/31/2014
Adding items
Remov ing items
Ref erring to individual elements
Counting items
Clearing the collection
Items property
Click on ellipses to open String
Collection Editor.
Ty pe list items, end each line with
Enter key .
Items.Add
Items.Insert
--OR--
7-7
7-8
Examples
Object.Items.Add(ItemValue)
Examples
SchoolsListBox.Items.Add("Harvard")
SchoolsListBox.Items.Add("Stanford")
SchoolsListBox.Items.Add(SchoolsTextBox.Text)
MajorsComboBox.Items.Add(MajorsComboBox.Text)
MajorsComboBox.Items.Add(MajorString)
SchoolsListBox.Items.Insert(0, "Harvard")
MajorsComboBox.Items.Insert(1, MajorsComboBox.Text)
7-9
7-10
Remember:
Items.Count is always one more than the highest
possible SelectedIndex, because indexes begin with 0
For example, if there are five items in a list:
Items.Count = 5
AND
Highest Index = 4
7-11
7-12
7/31/2014
Examples
NamesListBox.Items.RemoveAt(0)
' Remov e the item in position IndexInteger.
SchoolsComboBox.Items.RemoveAt(IndexInt
eger)
Cof feeComboBox.Items.RemoveAt(CoffeeCo
mboBox.SelectedIndex)
7-13
7-14
Examples
Clearing a List
Examples
SchoolsListBox.Items.Clear( )
MajorsComboBox.Items.Clear( )
7-15
7-16
Do/Loops
In the Editor window, select the control name in the Class Name
list (at the top-left of the window), drop down the Method Name list, and
select the event for which you want to write code or double-click the
event name in the Properties window after clicking the Events button.
The Editor will create the procedure header for you.
TextChanged Event
Occurs when user types text into combo box
List box does not have TextChanged Event.
Enter Event (control receives focus) an Enter event fires when a user
tabs from control to control.
Leave Event (control loses focus) a Leave event triggers as user tabs
between controls.
7-17
7-18
7/31/2014
Top of Loop
Condition,
P retest/Entry
test
--OR-Do
Bottom of
Loop
Condition,
P osttest/ Exit
7-19
7-20
7-21
For/Next Loops
7-22
7-24
7/31/2014
Exiting Loops
7-25
7-26
7-27
7-28
Appears in the
Component Tray
Execute the Print method
to start printing.
The code belongs in the
Click event procedure for
the Print button or menu
item that can be selected
to begin printing.
7-29
7-30
7/31/2014
What to print
What f ont and color to print in
Where to print
7-31
7-32
Examples
e.Graphics.DrawString(PrintLineString, PrintFont, Brushes.Black, _
HorizontalPrintLocationSingle, VerticalPrintLocationSingle)
e.Graphics.DrawString("My text string", MyFont, Brushes.Black, _
100.0, 100.0)
e.Graphics.DrawString(NameTextBox.Text, New Font("Arial", 10), _
7-33
7-34
PrintPageEventArgs
7-35
7-36
7/31/2014
7-38
7-39
7-40
PrintPreviewDialog Component
7-41
7-42
7/31/2014
Running totals
Running counts
Boolean switches
Storing current page number/count when printing
multiple pages
7-43
7-44