Download presentation
Presentation is loading. Please wait.
Published byLaurence Wilkins Modified over 9 years ago
1
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 2 More Controls
2
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 2 McGraw-Hill/Irwin More Controls Introducing more controls Working with multiple controls Designing your applications for user convenience Coding for the controls Programming hints
3
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 3 McGraw-Hill/Irwin Introducing More Controls Labels: lblName.Caption=txtName.Text Text boxes: txtName.Text=“French” Frames: Groups option buttons Check boxes: chkName.Value=0, 1 or 2.caption is name Option buttons: optButton.value=True or False Images
4
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 4 McGraw-Hill/Irwin Tools Introduced in Chapter 2 Check box Frame Shape Image Option button Text box Line
5
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 5 McGraw-Hill/Irwin Text Boxes Default property is.Text –txtLastName = “Frockmeister” sets.Text prop. Alignment property –0 (left) –1 (right) –2 (center) If you want the user to input information, you need a text box
6
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 6 McGraw-Hill/Irwin Frames Frames are containers for option buttons and check boxes, and are also used to format the appearance of a form Frames establish the mutually exclusive nature of option buttons: Frame Option buttons
7
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 7 McGraw-Hill/Irwin Check Boxes Select or deselect Yes/No options Default property is.Value Example: chkPrint.Value = 0 (no) 0 = no, 1 = yes (checked), 2=disabled check box
8
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 8 McGraw-Hill/Irwin Option Buttons Used for mutually exclusive choices such as color choices or Print All, Print Selection, or Print One Page Default property is.Value (0 or 1) Names: optBlue, optFontSize Option buttons
9
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 9 McGraw-Hill/Irwin Cautions with frames and buttons or boxes Frames are often used to group option buttons or check boxes. Draw the frame(s) first. Be sure to select the desired object’s tool with one click, and then drag and drop to draw the object inside the frame. Do not double click. That places the object in the form’s group. Do not just double click and then drag the object inside the frame. The object still “belongs”to the form.
10
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 10 McGraw-Hill/Irwin Images An image holds a picture (not an OLE object) Properties: –.Picture (the file name of an image to display) –.Stretch (picture fills control) –.Visible (true/false makes it appear/disappear) Example: imgFlag.Visible = False Let’s do it, See Feedback 2.1. Put your picture onto your Hello World form, just above, or to the left of your name.
11
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 11 McGraw-Hill/Irwin Shape Control Shape control places rectangles, squares, ovals, circles, or other shapes on a form Shape is determined by.Shape property Shape property value
12
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 12 McGraw-Hill/Irwin Line Control Draw lines on a form to separate elements Name example: linLogo A Line has very few properties: –BorderStyle –BorderWidth –BorderColor
13
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 13 McGraw-Hill/Irwin Working with Multiple Controls Selecting multiple controls Deselecting a group of controls Moving controls as a group Setting properties for multiple controls Aligning controls Read about these tricks on pages 57-60. Learning this can make your VB programming life much easier
14
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 14 McGraw-Hill/Irwin Designing Your Applications for User Convenience Designing the user interface (gray is good!) Defining keyboard access keys (Exit) –Use Windows-standard keys, when possible –Use x for Exit, S for Save –Type an ampersand (&) in front of the character you want for the access key E&xit for Exit –The user can then use Alt + x for exit, etc. –Do not give two controls the same access key!
15
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 15 McGraw-Hill/Irwin Default and Cancel Properties Setting command button Default and Cancel properties.Default = True or False.Cancel = True or False Why? A keyboard user can then use the Enter or Esc keys to accomplish the next logical task Example: OK and Cancel buttons Or, Make one of your command buttons the default button for quick calculations.
16
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 16 McGraw-Hill/Irwin Tab Order Property for Controls Setting the tab order property of controls –TabStop property (.Enabled = yes) Not all controls have this –TabIndex property (a value beginning at 0) Program sets focus on control with lowest TabIndex One control always has the focus –A light dotted line around the control, or the insertion point in a text box If you want to Tab in different sequence, or if you add objects later, you may need to adjust the TabIndex
17
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 17 McGraw-Hill/Irwin Coding for the controls Very important section – read pages 66-67 –Resetting the focus –Setting option buttons/check boxes value properties –Changing the font –Properties of controls –Changing multiple properties of a control –Continuing program lines Do Feedback 2.2
18
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 18 McGraw-Hill/Irwin Controls' Default Properties Each control has a default property A default property is the implied property for the object if you omit it following the object: –txtAddress = "1234 Somewhere Street" –chkPrint = True –lstChoice(index) = "14“ One way to discover what the default property is for a control is to put one on a form, and then note which property is highlighted.
19
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 19 McGraw-Hill/Irwin Programming Hints Check the tab order of an application Use the value property of a check box or option button to set other true/false properties. Ctrl-click a tool to repeatedly use tool Create an option button inside its frame Label controls are “read only” messages Text controls are input/output controls
20
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 20 McGraw-Hill/Irwin Review Questions - 1 of 2 1. You can display program output in a text box or a label. When should you use a text box? When should you use a label? 2. How does the behavior of option buttons differ from the behavior of check boxes? 3. If you want two groups of option buttons on a form, how can you make the groups operate independently? 4. Explain how to make a graphic appear in an image control. 5. Describe how to select several labels and set them all to 12-point font size in on operation [at design time]. 6. What is the purpose of keyboard access keys? How can you define them in your project? How do they operate at run time? 7. Explain the purpose of the Default and Cancel command button properties. 8. What is the focus? How can you control which object has the focus?
21
Programming in Visual Basic 6.0 Update Edition © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 21 McGraw-Hill/Irwin Review Questions - 2 of 2 9. How do you force the insertion point appear in a particular text box that may not have the lowest tabindex value? 10. Write the statement to force the focus to be on txtFirstName on a form. 11. What Basic statements will clear the current contents of a text box and a label? 12. Explain how to change a label's Caption to italic at design time and at run time. 13. How are the With and End statements used? Give an example. 14. What is concatenation and when would it be useful? 15. Explain how to continue a very long Basic statement onto another line. 16. What is the default property of a control? Give an example.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.