Chapter 2 More Controls Programming In Visual Basic

Chapter 2 More Controls Programming In Visual Basic. NET © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Controls in the Toolbox 2 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Button (btn) (review from Ch 1) • Used to run/activate an Event Procedure • Click event 3 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Label (lbl) (review from Ch 1) • Used for – Output on a form – Identification of objects – Directions/Information • Cannot by modified by user 4 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Text Box (txt) • Used for user input/data entry • Text Property – What is displayed in text box – What user entered in text box • Text. Align Property – Controls alignment of text in the Text Box • Change Event 5 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Group Box (grp) • Used as containers for other controls such as radio buttons and check boxes • Improves readability of form • Text Property – What is displayed on the top edge of the group box 6 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Check Box (chk) • Used for user input/data entry • Allows the user to select or deselect 1 or more in any group • Checked Property – Checked = True – Unchecked = False • Check. Changed Event 7 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Radio Button (rad) • Used for user input/data entry • Allows the user to select only 1 in any group • First create a group and then create each radio button inside the group • Checked Property – Checked = True – Unchecked = False • Check. Changed Event 8 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Picture Box (pic) • Displays/contains a picture/graphic • Image Property – Complete path and filename of graphic –. bmp, . gif (including animated), . jpg, . png, . ico, . emf, . wmf • Size. Mode Property – Stretch. Image causes graphic to be resized to match the size of the control • Visible Property 9 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Borders and Styles • Border. Style Property – None – Fixed. Single – Fixed 3 D 10 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Drawing a Line • Use Label Control – Text=blank – Border. Style=None – Back. Color=desired line color – Width and Height as desired • Use the Graphics Methods covered in Chapter 12 11 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Selecting Multiple Controls • SHIFT-Click or CTRL-Click to select/deselect multiple controls • Use the mouse to drag a selection box around multiple controls • To deselect all selected controls click elsewhere on the form 12 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Selecting Multiple Controls (cont. ) Start here Drag to here Using mouse to drag a selection box around multiple controls 13 Multiple selected controls, observe selection handles. © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

What Can be Done with Multiple Selected Controls? • Use Format Menu or Layout Toolbar to – Align them to each other – Make same size – Modify the spacing between them • Move them as a group • Set their common properties 14 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Designing the User Interface • To the user the Interface should be – Easy to understand – Familiar – Comfortable – Organized – Sans Serif Fonts are best, not boldface or large – Color Neutral Overall – Keyboard Accessible 15 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Keyboard Access Keys • • • Also referred to as Hot Keys Underlined Letter User presses ALT + underlined letter Use Windows-Standard Keys Defined using Text Property Text=&OK Text=E&xit 16 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Default & Cancel Buttons • Default Button – Identified visually on Form by its darker outline – Responds to ENTER key – Form's Accept. Button Property • Cancel Button – Responds to ESC key – Form's Cancel. Button Property 17 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Focus • One control on a Form always has the Focus • Not all control types can receive the focus • Tab. Stop Property (applicable only for controls that are capable of receiving the focus) – Designates whether a control is allowed to receive the focus; True or False 18 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Tab Order • User should be able to use TAB key to move the focus through a form in an organized manner; top to bottom, left to right • Tab. Index Property – Number in tab sequence – 0 for first control to receive the focus when the form loads • Use View Menu, Tab Order to set 19 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Setting Tab. Index Property • View menu, Tab. Order • Click on each control in sequence to set Tab. Index property of controls automatically 20 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Form's Screen Location • Start. Position Property – Manual – Center. Screen – Windows. Default. Location – Windows. Default. Bounds – Center. Parent 21 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Tool. Tips • Small label that is displayed when user places pointer on a control and pauses • Usually used with Command Buttons • Steps for creating Tool. Tips – Add a Tool. Tip Control to Form • Appears in the Component Tray, pane at bottom of Form Designer where nondisplay controls are shown – Set Tool. Tip on Tool. Tip 1 Property of each control to the text of tip 22 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Tool. Tip Control Component Tray 23 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Clearing Text Boxes & Labels • Set Text Property equal to the Empty String – Empty String is 2 quotation marks with no space between them ("") • Use the Clear Method of a Text Box txt. Name. Text = "" lbl. Message. Text = "" txt. Course. Clear( ) 24 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Resetting the Focus • Places the Insertion Point in a Text Box • Use the Focus Method txt. Name. Focus( ) 25 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Checked Property of Check Boxes and Radio Buttons • Selects/Deselects Check Box or Radio Button • Set Checked Property – True = Checked, selected – False = Unchecked, deselected rad. Red. Checked = True chk. Bold. Checked = False 26 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

VB Color Constants • Fore. Color and Back. Color Properties • Use VB Color Constants from the Color Class • View complete list in Help by using the keyword Color followed by a period txt. Name. Fore. Color = Color. Alice. Blue lbl. Message. Back. Color = Color. White 27 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

With and End With • Change several properties at once in Code • Will run more efficiently With txt. Name. Visible = True. Text ="Lynne". Focus( ) End With 28 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Concatenation • Think of it as "glueing" text strings together • Example: txt. FName contains First Name txt. LName contains Last Name lbl. Full. Name. Text = txt. FName. Text & " " & txt. LName. Text lbl. Note. Text = "Today's weather is " & txt. Weather. Text & ". " 29 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.

Continuing Lines of Code • For long lines of code it is more readable to continue them to the next line • At the end of the line type Line Continuation Character, a Space followed by an Underscore lbl. Message. Text = txt. FName. Text & "" & txt. LName. Text & _ ", welcome to Aiken Technical College. Today is " & _ txt. Today. Text 30 © 2001 by The Mc. Graw-Hill Companies, Inc. All rights reserved.
- Slides: 30