Chapter9 A Deeper Look In Controls Groupboxes Checkboxes

Chapter#9: A Deeper Look In Controls Groupboxes , Checkboxes, tooltips , listboxex, comobo. Boxes

Outlines 1. 2. 3. 4. 5. 6. Using Groupboxes and Panels Using a List Box for Input Using Combo box for Input Using Radio Buttons for Input Using Check Boxes for Input Events Raised by Selections © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 2

1. Group. Boxes and Panels They’re typically used to group several controls that are related in a GUI. All of the controls that you drag onto a Group. Box or a Panel move together when you move the Group. Box or Panel to a new position the Form in Design view. To attach controls to a group box, create the group box and then place the controls into the group box. © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 3

Group. Boxes and Panels Group. Boxes Panels Can display a text caption Cannot have scrollbars Can display scrollbars Example: Text Caption Example: © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 4

Groupboxes Changing the caption text of a group box © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 5

Example #1: Groupboxes This program will display in a label box the Text name of the pressed button in a Groupbox (Groupbox 1) Private Sub Button 1_Click(By. Val sender As System. Object, By. Val e As System. Event. Args) Handles Button 1. Click, Button 2. Click, Button 3. Click, Button 4. Click Label 1. Text = "You pressed " & CType(sender, Button). Text End Sub © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 6

Example#1: Output © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 7

Panels To enable the scrollbars, set the Panel’s Auto. Scroll property to True. Scrollbar © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 8

Panels When you click one of these Buttons, the event handler (lines 5– 11) changes the Text on the output. Label to "You pressed: " followed by the Text of the clicked Button. © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 9

Example#2: Panels © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 10

Example 2: Output © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 11

The Three Types of Controls Used for Selection list box radio buttons check boxes © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 12

2. List Boxes Fill a List Box at Design Time via its String Collection Editor Tasks button click here to invoke string collection editor © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 13

String Collection Editor Fill by direct typing or by copying and pasting from a text editor or a spreadsheet. © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 14

List Box at Run Time lst. Months selected item The value of the list box (lst. Months) is the string consisting of the selected item. © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 15

Example #3: Code for btn. Determine. Click Dim days. In. Month As String Select Case lst. Months. Text Case "September", "April", "June", "November" days. In. Month = "30" Case "February" days. In. Month = "28 or 29" Case Else days. In. Month = "31" End Select txt. Days. Text = days. In. Month © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 16

3. The Combo Box Control A list box combined with a text box The user has the option of filling the text box by selecting from a list or typing directly into the list box. Essentially same properties, events, and methods as a list box Drop. Down. Style property specifies one of three styles © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 17

Combo Box Styles © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 18

Styles at Run Time after Arrows are Clicked The value of combo. Box. Text is the contents of the text box at the top of the combo box. © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 19

Example#4 Private Sub btn. Display_Click(. . . ) _ Handles btn. Display. Click txt. Display. Text = cbo. Title. Text & " " & txt. Name. Text End Sub txt. Name cbo. Title © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais txt. Display 20

4. Radio Button Properties To determine if the button is selected or not If (rad. Button. Checked = true)Then Statement. . . End If rad. Button. Checked = False has value True if button is on. To turn a radio button on rad. Button. Checked = True © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 21

Example#5: Form rad. Child rad. Minor rad. Adult rad. Senior © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 22

Example 5: Code for Button If rad. Child. Checked Then txt. Fee. Text = Format. Currency(0) Else. If rad. Minor. Checked Then txt. Fee. Text = Format. Currency(5) Else. If rad. Adult. Checked Then txt. Fee. Text = Format. Currency(10) Else. If rad. Senior. Checked Then txt. Fee. Text = Format. Currency(7. 5) Else Message. Box. Show("Must make a selection. ") End If © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 23

Example#5: Output Note: Format. Currency() is a built-In function that displays the dollar sign ($) in the output © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 24

5. 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 has value True when check box is checked and False when not Checked. Changed event is raised when the user clicks on the check box © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 25

Example 6: Form chk. Drug chk. Dental chk. Vision chk. Medical © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 26

Example#6: Code for Button Important Note: Dim sum As Double = 0 If chk. Drugs. Checked Then We used here simple sum += 39. 15 If. . . Then. . . End. If statement to check the selection of the End If checkboxes instead of using If chk. Dental. Checked Then If. . Then. . . Else. . . End. If sum += 10. 81 The reason: when we find one End If checkbox is selected we can If chk. Vision. Checked Then continue checking the other sum += 2. 25 checkboxes if they were selected End If or not If chk. Medical. Checked Then sum += 55. 52 End If txt. Total. Text = Format. Currency(sum) © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 27

Example #6: Output © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 28

Events Raised by a Selection Selected. Index. Changed – raised when a new item of a list box is selected Checked. Changed - raised when the user clicks on an unchecked radio button or a check box; that is, when the value of the Checked property is changed. © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 29

Example #7: Code Private Sub check. Box_Changed(. . . ) Handles _ chk. Drugs. Checked. Changed, chk. Dental. Checked. Changed, chk. Vision. Checked. Changed, chk. Medical. Check. Changed Dim sum As Double = 0 If chk. Drugs. Checked Then sum += 39. 15 End If (continued on next slide) © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 30

Example #7: Code (continued) If chk. Dental. Checked Then sum += 10. 81 End If If chk. Vision. Checked Then sum += 2. 25 End If If chk. Medical. Checked Then sum += 55. 52 End If txt. Total. Text = Format. Currency(sum) End Sub © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 31

Example #7: Output © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 32

7. The Tool. Tip Control Appears in component tray of form with default name Tool. Tip 1 Allows a tooltip to appear when user hovers over a control (such as a text box) Text displayed in tooltip is the setting of the “Tool. Tip on Tool. Tip 1” property of the control to be hovered over © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 33

Example #8 : Form txt. Rate “Tool. Tip on Tool. Tip 1” property of txt. Rate has the setting “Such as 5, 5. 25, 5. 5 …” © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 34

Example #8: Output © 1992 -2011 by Pearson Education, Inc. All Rights Reserved-Edited by Maysoon Al. Duwais 35
- Slides: 35