You are on page 1of 6

CREATED BY: VISHAL RANE JUL, 1

Chapter 2- More Controls ANSWERS TO REVIEW QUESTIONS


1.

You can display program output in a text box or a label. When should you use a text box? When would a label be appropriate? A text box should be used when the user will be allowed to type some input or change what is displayed. A label will only display program output to the user. The user will not be allowed to change what is displayed in a label. How does the behavior of option buttons differ from the behavior of check boxes? In a group of check boxes, any number of boxes may be selected. Option buttons are used when only one button of a group may be selected. If you want two groups of option buttons on a form, how can you make the groups operate independently? In order to create two groups of option buttons that operate independently you should place each group inside of its own frame. A group of option buttons inside a frame function together as a group. The best method is to first create a frame, then create each option button inside the frame. You must be careful to create the button inside the frame; dont create it on the form and drag it inside the frame- it still belongs to the forms group, not the frames group. Explain how to make a graphic appear in an image control.

ANS:-

2.

ANS:-

3.

ANS:-

4.

ANS:First place the image control on a form, then select its Picture property in the Properties window. You can set an images Picture property to a file with an extension of .BMP, .WMF, .ICO,.DIB, .GIF, .JPG, .EMF, or .CUR.. Image controls have several useful properties, which you can set at design time or run time. For example, set the Stretch property to True to make the picture enlarge to fill the control. You can set the Visible property to False to make the image disappear.

CREATED BY: VISHAL RANE JUL, 1

5.

Describe how to select several labels and set them all to 12-point font size with one command.

ANS:There are two methods of selecting multiple controls. If the controls are near each other, the easiest method is to use the mouse to drag a selection box around the controls. Point to one corner of a box surrounding the controls, press the mouse button, and drag to the opposite corner. When you release the mouse button, each of the controls will have light gray selection handles. You can also select multiple controls, one at a time. First click on one control to select it, then hold down the Ctrl key or the Shift key and click on the next control. You can keep the Ctrl or Shift key down, and continue clicking on controls you wish to select. Ctrlclick (or Shift click) on a control a second time to deselect it without changing the rest of the group. With the labels still selected, scroll to the Font property and click to select it. The Settings box shows the currently selected size Click on the Properties button (with an ellipses on top); the ellipses indicates clicking on the button will display the Font dialog box. Select point size 12. 6. What is the purpose of keyboard access keys? How can you define them in your project? How do they operate at run time?

ANS:Windows is set up so that most everything can be done with either the keyboard or the mouse. You can make your projects respond to the keyboard, by defining access keys. You can set access keys for command buttons, option buttons, and check boxes when you define their Caption properties. Type an ampersand (&) in front of the character you want for the access key; Visual Basic underlines the character. During run time you can operate the keyboard access keys by pressing and holding Alt + the key that corresponds to the underlined character. For example, use the Exit button with Alt + x.

CREATED BY: VISHAL RANE JUL, 1

7.

Explain the purpose of the Default and Cancel properties of command buttons. Give an example of a good use for each.

ANS:Once a person's fingers are on the keyboard to type, most people prefer to press common keys rather than pick up the mouse. The Enter key is commonly used to finish a task. Setting the Default property of a command button to True will allow the user to press Enter and the effect will be the same as clicking the command button. The cancel button is the button that is selected when the user presses the Esc key. You can make a command button the cancel button by setting its Cancel property to True. An example of a good time to set the Cancel property is on a form with OK and Cancel buttons. You may want to set the Default property to True for the OK button, and the Cancel property to True for the Cancel button. 8. What is a ToolTip? How can you make a ToolTip appear?

ANS:ToolTips are small labels that pop up when you pause your pointer over a toolbar button or control. You can make a ToolTip appear for the controls on your form by setting the controls ToolTipText property to the text that you want to display. 9. What is the focus? How can you control which object has the focus?

ANS:In Windows programs, one control on the form always has the "focus." You can see the focus change as you Tab from control to control. For controls such as command buttons and option buttons, the focus appears as a light dotted line. For text boxes, the insertion point (also called the cursor) appears inside the box. Some controls, such as labels and images, cannot receive the focus. Two properties determine whether the focus stops on a control and the order in which the focus moves. Controls that are capable of receiving focus have a TabStop property, which you can set to True or False. If you do not want the focus to stop on a control when the user presses the Tab key, set the TabStop property to False.The TabIndex property determines the order the focus moves as the Tab key is pressed. As you create controls on your form, Visual Basic assigns the TabIndex property in sequence. Most of the time that order is correct, but if you want to Tab in some other sequence or

CREATED BY: VISHAL RANE JUL, 1

you add controls later, you will need to modify the TabIndex properties of your controls. 10. Assume you are testing your project and dont like the initial position of the insertion point. Explain how to make the insertion point appear in a different text box when the program begins. ANS:The TabIndex property determines the order the focus moves as the Tab key is pressed. As you create controls on your form, Visual Basic assigns the TabIndex property in sequence. Probably, most of the time, that order is correct. But if you want to Tab in some other sequence, or you add controls later, you will need to modify the TabIndex properties of your controls. When your program begins running, the focus is on the control with the lowest TabIndex (usually zero). Since you want the insertion point to appear in the first text box on the form, its TabIndex should be set to zero. The next text box should be set to 1; the next to 2; and so forth. 11. During program execution you want to return the insertion point to a text box called txtAddress. What Basic statement will make that happen? txtAddress.SetFocus

ANS:-

12. What Basic statements will clear the current contents of a text box and a label? ANS:You can clear out the contents of a text box or label by setting the property to an empty string. Use "" (no space between the two quotation marks). Remember that labels use a caption property, and text boxes use a text property. 13. Explain how to change a labels Caption to italic at design time and at run time.

ANS:In design time you can change a labels Caption to italics by choosing Font in the Properties window and display the Font dialog box. There you can change the name of the font, the size, the style (bold, italic, underline), and the color. At run time you use a special object called a Font object. You can set the

CREATED BY: VISHAL RANE JUL, 1

italics property for the Font object, and access it through the Font property of a control. For example, a label named lblTitle will have the font changed to italic using the following code: lblTitle.Font.Italic = True 14. How are the With and End With statements used? Give an example. ANS:The With and End With statements are used to change several properties of a single control. You specify an object name in the With statement. All subsequent statements until the End With relate to that object. Example: With txtTitle .Visible = True .ForeColor = vbWhite .Font.Bold = True .Font.Italic = True .SetFocus End With 15. What is concatenation and when would it be useful?

ANS:Concatenation is a process where you can "tack" one string of characters to the end of another. Use an ampersand (&), preceded and followed by a space, between the two strings. Concatenation is very useful when you want to join a string literal and a property. For example: lblMessage.Caption = "Your name is: " & txtName.Text 16. Explain how to continue a very long Basic statement onto another line. ANS:When a Basic statement becomes too long, you can use the linecontinuation character. You can type a space and an underscore at the end of the line, press Enter, and continue the statement on the next line. It is OK to indent the continued lines. The only restriction is that the linecontinuation character must appear between elements; you cannot place a continuation in the middle of a literal, or split the name of an object or property.

CREATED BY: VISHAL RANE JUL, 1

17. What is the default property of a control? Give an example. ANS:Each class of control has one property which is the default property. When you use the default property of a control, it isn't necessary to name the property. For example, the Text property is the default property for a text box. These two statements are equivalent: txtCompany.Text = "R 'n R -- for Reading 'n Refreshment" txtCompany = "R 'n R -- for Reading 'n Refreshment"

You might also like