446 449




Visual Basic 6 Black Book:The Frame, Label, Shape, And Line Controls
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




Aligning Text In Labels
As with text boxes, you can align text in labels. To do that, you just set the label’s Alignment property at design time or runtime. Here are the possible values for the Alignment property:

•  VbLeftJustify—0 (the default); text is left-aligned
•  VbRightJustify—1; text is right-aligned
•  VbCenter—2; text is centered

For example, if you’re writing a calculator program and have a column of right-justified text boxes above a label that displays a running sum, you can also right-justify the label to match the controls above it.

Handling Label Control Events
Here’s something that even experienced Visual Basic programmers often don’t know: labels have events like Click and DblClick (although they don’t have any keystroke-handling events). Using these events can be a good thing if you’re using a label control as more than just a label—for example, to reset a setting of some kind.
Here’s an example using the DblClick event. We developed a stopwatch program in our chapter on timers (Chapter 13) and displayed the elapsed time in a label named Display in that program. To make life easier for users, we can let them just double-click that label to reset the stopwatch to 00:00:00. Doing so is easy; we just add an event handle for the label’s DblClick event:


Private Sub Display_DblClick()

End Sub


To reset the stopwatch, we just use the Visual Basic Now function to set the start time, held in a variable named StartTime, to the current time:


Private Sub Display_DblClick()
StartTime = Now
End Sub


And that’s it. Now when the user double-clicks the stopwatch’s display, the stopwatch is reset to 00:00:00. We’ve made effective use of a label’s DblClick event.
Using Labels To Give Access Keys To Controls Without Captions
The Testing Department is calling again. The old thorny issue of keyboard access has come up again. Theoretically, they say, users should be able to use your program, SuperDuperDataCrunch, with just the keyboard. Fine, you say, we can add access keys to all the button captions so the user can give the button the focus just by pressing Alt + the access key (just like menu items). Don’t forget to do the same to all the text boxes, the testing department says. You think, how do you give an access key to a text box?
This is where a useful aspect of labels comes in handy. In fact, this aspect of the label control is built just to handle this problem. You can give access keys to controls with Caption properties just by placing an ampersand (&) in the caption in front of the letter you want to make the access key—but how can you do that if a control (like a text box) has no Caption property?
Here’s the way you do it: you give the access key to a label control and then make sure the control you want to give the focus to with that access key is next in the tab order (that is, has the next highest TabIndex property value). Because labels cannot accept the focus themselves, this is a neat feature: when the user presses Alt + the access key, the label passes the focus on to the next control. In this way, you can give even controls without Caption properties access keys.

WARNING!  When you use access keys, make sure you set the label’s UseMnemonic property to True (the default), or the access key won’t be enabled.

As an example, we’ve given the two labels in Figure 14.9 access keys. When the user presses Alt + the access key above a text box, the focus is set to that text box, because those text boxes follow their individual labels in the tab order.


Figure 14.9  Using access keys in labels to give the focus to text boxes.
Now we’re using access keys with text boxes.

Adding A Shape Control To A Program
The Aesthetic Design Department is calling again. Can’t you jazz up the appearance of your program a little? How about something to give it a little pizzazz? Looking around, you happen to notice the shape control. OK, you say, no problem.
You use the shape control at design time to draw shapes on a form or picture box. The shapes you can draw are rectangles, squares, ovals, circles, rounded rectangles, and rounded squares.
At runtime, you can access and change the shape control’s properties like Left, Top, Width, Height, BackColor, FillStyle, or FillColor, and use its methods, like Move or Refresh. However, shape controls have no events, so they can’t respond directly to user actions like clicks.
You draw a shape using the Shape Control tool, which appears in the Visual Basic toolbox when Visual Basic starts. Just draw the shape as you want it (it starts as a rectangle). To set the shape’s type (for example, a rectangle, square, oval, and so on), you set the control’s Shape property to one of the following values:

•  VbShapeRectangle—0 (the default); rectangle
•  VbShapeSquare—1; square
•  VbShapeOval—2; oval
•  VbShapeCircle—3; circle
•  VbShapeRoundedRectangle—4; rounded rectangle
•  VbShapeRoundedSquare—5; rounded square

One important use of shape controls is to group other controls together. (Note, however, that shape controls can’t act as true control containers in the way picture boxes or frames can. For example, you can’t group option buttons together with shapes.) In Figure 14.10, we’re using shape controls to group the buttons visually into two groups.


Figure 14.10  Using the shape control to group other controls.
You can also set the width of the shape’s drawing line with the BorderWidth property and fill the shape using the FillColor and FillStyle properties. The BorderStyle property lets you select the style of the shape’s drawing line, including using dots and dashes. For more on this control, see the other topics in this chapter.



Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
02 (449)
README (446)
446 a
447 449
449 Przychody i koszty z tytułu wniesienia aportu do sp z o o
443 446
02 (446)
13 (446)
440 449

więcej podobnych podstron