225 230




Visual Basic 6 Black Book:Command Buttons, Checkboxes, And Option Buttons
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




Chapter 7Command Buttons, Checkboxes, And Option Buttons


If you need an immediate solution to:
Setting A Button’s Caption
Setting A Button’s Background Color
Setting Button Text Color
Setting Button Fonts
Reacting To Button Clicks
Creating Button Control Arrays
Resetting The Focus After A Button Click
Giving Buttons Access Characters
Setting Button Tab Order
Disabling Buttons
Showing And Hiding Buttons
Adding Tool Tips To Buttons
Resizing And Moving Buttons From Code
Adding A Picture To A Button
Adding A Down Picture To A Button
Adding Buttons At Runtime
Passing Buttons To Procedures
Handling Button Releases
Making A Command Button Into A Cancel Button
Getting A Checkbox’s State
Setting A Checkbox’s State
Grouping Option Buttons Together
Getting An Option Button’s State
Setting An Option Button’s State
Using Graphical Checkboxes And Radio Buttons
Using Checkboxes And Option Buttons Together

In Depth
In this chapter, we’re going to take a look at what are arguably the most popular controls in Visual Basic: buttons. These include command buttons, checkboxes, and option buttons.

Command buttons—the plain buttons that you simply click and release—are the most common type of buttons. These are the buttons you see everywhere in Visual Basic applications. They are usually just rounded, rectangular, gray buttons with a caption.
Checkboxes are also familiar controls. You click a checkbox to select it and click it again to deselect it. When you select a checkbox, a checkmark appears in it, indicating that the box is indeed selected.
Option buttons, also called radio buttons, are like checkboxes in that you select and deselect them. However, they are round, whereas checkboxes are square, and you usually use option buttons together in groups. In fact, that’s the functional difference between checkboxes and option buttons: checkboxes can work independently, but option buttons are intended to work in groups. When you select one option button in a group, the others are automatically deselected. For example, you might use checkboxes to select trimmings on a sandwich (of which there can be more than one), whereas you might use option buttons to let the user select one of a set of exclusive options, like the current day of the week.
You use tools in the toolbox to add command buttons, checkboxes, and option buttons to a form. In the toolbox in Figure 7.1, the Command Button tool is third down on the right, the Checkbox tool is fourth down on the left, and the Option Button tool is fourth down on the right.

Figure 7.1  The Command Button tool, the Checkbox tool, and the Option Button tool.
How This Chapter Works
Because the three different types of buttons have many similar characteristics, it makes sense to cover them in the same chapter. In fact, the three types of buttons have so many properties and methods in common that when covering such topics, we’ll refer to command buttons, checkboxes, and option buttons collectively as buttons.
For example, all three controls have a Caption property, so when we cover how to set captions in those controls, we’ll refer to them collectively as buttons. The title of that topic, then, is “Setting A Button’s Caption.” If we’re covering something that refers to one type of button exclusively, I’ll indicate that in the title of the topic, for example, “Grouping Option Buttons Together.” In this way, we’ll be able to address both what all the buttons have in common and what makes them useful independently.
That’s all the introduction we need—we’ll turn to the Immediate Solutions now.
Immediate Solutions
Setting A Button’s Caption
You use a button’s Caption property to set its caption. This property is available at both design time and runtime.
After you add a button to a form, you set its caption by placing the appropriate text in the Caption property in the Properties window. You can also change the button’s caption at runtime, of course. As an example, we’ll use our tic-tac-toe program from Chapter 1:


Private Sub Form_Load()
xNow = True
End Sub

Private Sub Command_Click(Index As Integer)
If xNow Then
Command(Index).Caption = "x"
Else
Command(Index).Caption = "o"
End If

xNow = Not xNow

End Sub



TIP:  It’s useful to be able to change the captions of buttons. For example, if a command button’s caption reads Connect To Internet, then when you’re connected you could change the button’s caption to Disconnect From Internet, and disconnect from the Internet when the button is clicked.

Setting A Button’s Background Color
You’ve got your program running at last, but now the Aesthetic Design Department is on the phone. The “emergency” window in your program is colored red—why not the Panic button in the middle of that window also?

So, how do you do that? You can use the button’s BackColor property, as shown in Figure 7.2. Note that you also have to set the button’s Style property to Graphical (which has a numeric value of 1). We’ll see more about graphical buttons later in this chapter. Here, we’re setting the background color of a button at design time, and two sets of colors are available: a set of standard Visual Basic control colors (like “Button Face,” “Button Shadow,” and so on), and a palette of colors.

Figure 7.2  Setting a button’s background color.
You can also set the button’s BackColor property at runtime, setting it to a value using the RGB() function, which takes three parameters (0 to 255) for the red, green, and blue color values you want to set. Here, we change the color of a graphical button to red:


Command1.BackColor = RGB(255, 0, 0)






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:
25 (230)
Dz U 2005 225 1934 Czynności kontrolno rozpoznawcze przeprowadzane przez Państwową Straż Pożarną
225 226
05 (230)
230 235
230,23,artykul
index (230)
moje 225
230 233
tyt (225)
KT100 230 KTY 10x 23x [INF]

więcej podobnych podstron