473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Turning a radio button into a toggle button

I would like to create a toggle button, so I chose a radio and set its
apperance to button. Is seems my method always makes this .checked = false.
Can somebody help me to see the error in my ways? I'm guessing that I just
need an event that triggers before it actually changes the value of the
button.

Private Sub radSound_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles radSound.Click
If radSound.Checked = True Then radSound.Checked = False Else
radSound = True
End Sub

--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog: http://sprayberry.typepad.com/ciaccio

Jun 27 '08 #1
8 11637
I've got a very clunky workaroud: two buttons "Sound" and "No Sound" (see
code), but there's go to be a more elegant way :) Thanks!

Private Sub radSound_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles radSound.Click
radSound.Checked = True
radNoSound.Checked = False
radSound.Visible = False
radNoSound.Visible = True
End Sub
Private Sub radNoSound_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles radNoSound.Click
radNoSound.Checked = True
radSound.Checked = False
radNoSound.Visible = False
radSound.Visible = True
End Sub

Jun 27 '08 #2
Jeff Ciaccio wrote:
I would like to create a toggle button, so I chose a radio and set its
apperance to button. Is seems my method always makes this .checked =
false. Can somebody help me to see the error in my ways? I'm guessing
that I just need an event that triggers before it actually changes the
value of the button.

Private Sub radSound_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles radSound.Click
If radSound.Checked = True Then radSound.Checked = False Else
radSound = True
End Sub
Jeff,

I'd use a Checkbox control with the Appearance set to Button instead of
the Radio control. Then you don't need any code to control what it
looks like you are trying to do. If you can tell me what you are
attempt to accomplish with the code, I'd be very willing to attempt to
help you more.

Andrew Cooper
Jun 27 '08 #3
Hey Andrew,

I just want to allow the user to toggle the sound on and off.
If you can tell me what you are
attempt to accomplish with the code, I'd be very willing to attempt to
help you more.

Andrew Cooper
Jun 27 '08 #4
Jeff Ciaccio wrote:
Hey Andrew,

I just want to allow the user to toggle the sound on and off.
>If you can tell me what you are attempt to accomplish with the code,
I'd be very willing to attempt to help you more.

Andrew Cooper
That's what I thought. Use the Checkbox control and not the Radio
control. Then all you need is the following event.

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

If CheckBox1.Checked = True Then
'Turn sound on.
Else
'Turn sound off.
End If
End Sub
Jun 27 '08 #5
Thanks - that did the trick. Why I didn't think of that ... :(

"Andrew Cooper" <ka************@gmail.comwrote in message
news:OX****************@TK2MSFTNGP02.phx.gbl...
Jeff Ciaccio wrote:
>Hey Andrew,

I just want to allow the user to toggle the sound on and off.
>>If you can tell me what you are attempt to accomplish with the code, I'd
be very willing to attempt to help you more.

Andrew Cooper

That's what I thought. Use the Checkbox control and not the Radio
control. Then all you need is the following event.

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

If CheckBox1.Checked = True Then
'Turn sound on.
Else
'Turn sound off.
End If
End Sub
Jun 27 '08 #6
Jeff Ciaccio wrote:
Thanks - that did the trick. Why I didn't think of that ... :(
Jeff,

Everything seems obvious after the fact. :-) If we all posted the times
we overlooked something simple everyone one of us would look pretty silly.

Andrew
Jun 27 '08 #7
On Jun 26, 10:12 pm, "Jeff Ciaccio" <non...@noreply.orgwrote:
Hey Andrew,

I just want to allow the user to toggle the sound on and off.
If you can tell me what you are
attempt to accomplish with the code, I'd be very willing to attempt to
help you more.
Andrew Cooper
You can use a checkbox to do it even with its text:

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
' Turn on sound - code here
' Also,
CheckBox1.Text = "Sound: ON"
ElseIf CheckBox1.Checked = False Then
'Turn off sound
' Also,
CheckBox1.Text = "Sound: OFF"
End If

End Sub

And still if you want to use radio buttons, then you'd need 2 radio
buttons like named "radiobutton1" and "radiobutton2" :

Private Sub RadioButton1_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RadioButton1.CheckedChanged
If RadioButton1.Checked = True Then
'Turn on Sound - Code here
MsgBox("Sound is turned ON")
End If
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
' Turn off Sound - Code here
MsgBox("Sound is turned OFF")
End If
End Sub
Hope this helps,

Onur Güzel
Jun 27 '08 #8
>
Everything seems obvious after the fact. :-) If we all posted the times
we overlooked something simple everyone one of us would look pretty silly.

Andrew
Right

:-)

Cor

Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MarthaR | last post by:
I am trying to add the current time to a field when the user clicks on the toggle button next to the field. I am getting a time of 12:00:00 AM each time I click the button. How do I get a...
4
by: Neil Coleclough | last post by:
I am constructing a database to process product returns for my Company. I have a number of toggle buttons to identify the stage to which each return has been processed. For example, clicking the...
2
by: Mel | last post by:
Hi, is there any way I can implement toolstrip toggle button simular to the MS Word alignment button? if one toggle button already pressed down, if user click on the "pushed down button", the...
3
by: Killer42 | last post by:
Hi all. I have a frame with some toggle buttons in it. All is working fine, except that the user can't tell which option is selected to begin with. How do I set one of the toggle buttons to the...
5
JustJim
by: JustJim | last post by:
Hi All I have a little application I'm working on for the local Department of Education. There is a "Main Menu" form that has a toggle button on it to show/hide the Database Window. When it is...
1
by: Jeffrey Christiansen | last post by:
I wanted to add a toggle button to a VB2005 form to be used for a simple Windows Application (i.e. compiled to a "*.exe"), so I added the ActiveX Microsoft Forms Object toggle button, however I...
6
by: ethanhines | last post by:
I am trying to dynamically change the value of a filed using a toggle button in a form it is not a yes or no question. I want it to change a value in a table based on it"s state. Toggled on="6...
1
by: =?Utf-8?B?R3JlZw==?= | last post by:
I've been looking for a Toggle Button style control and can't seem to find anything. I want to have two buttons on the screen with only one of the two being pushed down (or true). One of the two...
0
by: ARC | last post by:
Hello all, In access 2007, it appears you cannot put a toggle button underneath a menu id and have it show a Pressed / Not Pressed status. If you make the toggleButton ID as part of the main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.