After the
CheckBox
is enabled, you can click it. This time, the code calls the
cbChecked_Click
sub-procedure. The code checks the
cbChecked.Value
property and displays the appropriate message box. Again, the control auto-
matically changes the value, so you don’t have to keep track of it.
You could easily exchange the roles of the controls in this case. There’s
no reason
to avoid using the
ToggleButton
as a yes/no indicator or the
CheckBox
as an on/off toggle. However, when you build your application,
you need to consider how the visual presentation affects you. Although the
two controls work precisely the same, the
ToggleButton
does
present as
an on/off switch and the
CheckBox
does present as a yes/no indicator.
Making choices with option
buttons and frames
You never use the
OptionButton
control alone.
This control always appears
in a group. A group of
OptionButton
controls lets you make one selection
from a list of selections. Only one
OptionButton
control is selected at any
given time, so selecting one automatically deselects all the other buttons.
Because the
OptionButton
controls
work in a group, you have to tell VBA
which controls belong to which group, especially if a form contains more
than one group. You can create groups in one of two ways. The first technique
is to
add the same string to the
GroupName
property of each memory of the
group. The advantage of using this method is that it requires less space and
can make your program work faster. In addition, this method is transparent,
so any background image you use on the form shows through.
The second
method is to place the
OptionButton
controls in a
Frame
con-
trol. To use this technique, you must create the
Frame
control first and then
place the
OptionButton
controls within the
Frame
control.
The advantage
of using this method is that it’s less error prone (the first method depends
on you typing the same string each time and not making a typo), and you
can visually see which buttons belong in the same group. Frames can also
provide special visual effects, such as a sunken control group.
Unfortunately,
a group of
OptionButton
controls still acts as individual con-
trols. You have to monitor each control separately.
One way to monitor option button groups is to create a global variable and
use the
Click
event of each control to change it. This method provides a
slight performance boost because you don’t have to determine which
OptionButton
is selected when you want to perform a task —
the status
is always known. The disadvantages of this method are that it requires
slightly more code and a little more memory, and the global variable could
167
Do'stlaringiz bilan baham: