Hi All!
I want to creat 4 or 5 buttons
that the user can press only one button each time.
When a button is pressed the other ones are at off state.
Does the Visual Basic have such buttons?
If yes, How can I add those components?
Thanks a lot!
Y
Printable View
Hi All!
I want to creat 4 or 5 buttons
that the user can press only one button each time.
When a button is pressed the other ones are at off state.
Does the Visual Basic have such buttons?
If yes, How can I add those components?
Thanks a lot!
Y
When user Click one buttons, disable other buttons.
WHta'is your problem...?
Yes, they're called OptionButtons, which are also known as Radio Controls or Radio Buttons. They are standard controls that should be in your Tool Box. Only one can be clicked (selected) at a time.
How I add them to the Tool Box?
Li9erYol
When you click the Toolbox icon on the menu bar, do you
see a "recessed" white circle with a black dot in the center
(when you move your mouse over it, it should read OptionButton)?
That is, it should already be in the ToolBox, so you don't need to
add it "to the ToolBox"
If you mean, how do you add it to a form, then one way is to
1. add a Frame to the form
2. add an OptionButton to the Frame.
3. copy (Ctrl-C) the OptionButton, and paste it (Ctrl-V) to the Frame (not the form)
4. You will get a dialogue box asking you if you want to create a control array. Click YES.
5. Repeat step 3 (you won't be asked any more about creating a control array)
When you have put the 5 OptionButtons on the Frame, they will "act together"
since they are all within a common control (ie, the Frame)
HTH
Spoo
What Spoo said about creating an OptionButton Array is true but the OptionButton does not need to be in array to have only one active at a time. It's the nature of OptionButtons to have only one of them active at a time. ;)
CDRIVE
Oops.. thanks for the correction. Who knew?
Spoo
And to add one more thing. If you don't want the radio button visual effect, you can set the option button's Style property to Graphical then they will appear like command buttons, with a slight twist.
Now you tell me! :thumb:
After over 20 years I never knew this existed and always used command buttons to illustrate multiple choice question options (A, B, C, D, or E). The option buttons were always there for the taking and I think they look better and would have worked better for indicating a choice. I have half a dozen VB reference books that failed to address this. Gasp! :eek2:
Well, that check box isn't so exasperating. Seldom do authors of test items allow for more than one answer to an objective question, such as multiple choice or true/false. However, having an option for the standard check mark would have been a pleasant change on occasion for multiple topic selections.
Alas, Fox, that is not what has led to my demise. Not being able to port my VB6 programs directly into the Macintosh has sounded the death knoll. It's a classic case of the sponsor letting the tail wag the dog. :sick:
Hi All!
First of all, Thanks U 4 all the answers!
I already have 4 OptionButton in the frame,
I add another 5 option buttons and one I press in one of them the other 4 previous button are affected.
I read that you write about it,
But I dont know how to solve it
What can I do?
How I add radio button visual effect and set the option button's Style property to Graphical then they will appear like command buttons, with a slight twist. ?
10X
Y
put the second set in a different frame, or better to use picture boxes as frames have issues with xp style buttons, and may be a problem later
Can I do it in the same frame?
And if not,
How I add another frmae/form?
all radio buttons on a form or in the same frame are a single group, whether they are a control array or single controls
add a frame from the controls toolbox and make sure that the second set of radio buttons are in then moved into the new frame
or you can move controls into other containers (form, frames or pictureboxes), by code
set radio1.parent = frame2
I like to add a real world analogies to CommandButtons vs OptionButtons. In the real world a CommandButton is roughly equivalent to a Push Button (Momentary) Switch. Unlike a momentary switch though, its Value=True property is True from the moment of the Click and remains True, until End Sub is executed. If you have code that takes 15 seconds to complete (in the Click Event), it will remain True for that period. Yeah, anal I know, but I tested this! :bigyello:
On the other hand, OptionButtons are analogous to an array of mechanically interlinked locking push buttons, like the old auto radios had. Push any button and the one that was previously pressed pops out. A greater distinction though is its Value property, as it's Value remains True as long as it's the one that's selected, like a toggle switch remains closed until you switch it off.
Test setup for CommandButton's Value. Click Cmd1 to start the loop, then click Cmd2 to return its value while it's looping. It will return True until End Sub. When the loop finishes, click Cmd2 again. Cmd1 will return False.
Code:
Option Explicit
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To 20000 ' loop to kill time.
Me.Caption = i
DoEvents
Next i
End Sub
Private Sub Command2_Click()
MsgBox "Command1.Value = " & Command1.Value ' click while and after looping.
End Sub
my badQuote:
Set radio1.Container = frame2, I believe
Thanks for all the answers!
Another question,
Can I make a 5 square buttons that when the user clik on them, it seems like it pressed?
Thanks
Y
I have no idea what you're asking because if you set the OptionButton's Style to Graphical it's obvious when they're selected.
Unless they are placed in a disabled frame/picturebox. Then they look normal, but won't be clickable.
li9erYol, you have us all guessing. I think it is best if you provide a very detailed explanation of how you set your buttons up, what controls you eventually used, and describe the frame properties that those buttons were placed in.