Question toggle button color

hmvrulz

Member
Joined
Jul 17, 2008
Messages
9
Programming Experience
Beginner
for my college project i have have to design a GUI using .net which is XP compatible..


basically it has many buttons like ON/OFF n set some degree etc..

can sme one tell me how to create a Toggle Button
ON/OFF n color should change to GREEN/RED

i don knw Vb .net
just leanring it for this project
 
wat i would do, its set the button to green at form load

then have a button click event, if its green, then change the bottom color to red and vice versa
 
wat i would do, its set the button to green at form load

then have a button click event, if its green, then change the bottom color to red and vice versa
can u expain exactly wht i have to do.... i am new to this.
i little extra spoon feeding is helpful
 
Set the backcolor of the button to Green in designer properties window. Doubleclick the button to have the default event Click generated, add this code:
VB.NET:
If Me.Button1.BackColor = Color.Green Then
    Me.Button1.BackColor = Color.Red
Else
    Me.Button1.BackColor = Color.Green
End If
 
TIP: You also need to make some other difference visible between the Off / On states. I did the Red / Green thing, and then found that 4 of my users are red/green colourblind.


Oh, and have you tried using a Checkbox with Appearance set to Button?
 
Set the backcolor of the button to Green in designer properties window. Doubleclick the button to have the default event Click generated, add this code:
VB.NET:
If Me.Button1.BackColor = Color.Green Then
    Me.Button1.BackColor = Color.Red
Else
    Me.Button1.BackColor = Color.Green
End If

thanx... i wil get back if i have any queries
 
The code example's already been posted, if the color equals a certain color set it to the other color, other wise set it to the certain color
 
And how hard would that be?
VB.NET:
With Me.Button1
    If .BackColor = Color.Green Then
        .BackColor = Color.Red
        .Text = "OFF"
    Else
        .BackColor = Color.Green
        .Text = "ON"
    End If
End With
 
Fair enough, I'd forgotten that, sorry.

hehe u don need to be sorry.... your saving my ass here....i ahve got stuck with this vb project in college... n its not my area....


can u help me create a text filed where i can enter value from o deg to 360 deg...

if other values are entered its should accept but not give a error messsage also.
 
Yes, use the NumericUpDown control for that. Set the NUD's Minimum property to 0 (zero) and the Maximum property to 360. For a number range that large, I'd set the Increment property to 10 so if they used the up/down button's on the NUD it'd increase/decrease by 10 instead of 1.

Then when you need to grab the number from the control, don't use the Text property, use it's Value property because that properties a Decimal, which is already a numeric value (no conversion from String to number)
 
Yes, use the NumericUpDown control for that. Set the NUD's Minimum property to 0 (zero) and the Maximum property to 360. For a number range that large, I'd set the Increment property to 10 so if they used the up/down button's on the NUD it'd increase/decrease by 10 instead of 1.

Then when you need to grab the number from the control, don't use the Text property, use it's Value property because that properties a Decimal, which is already a numeric value (no conversion from String to number)

back with a noob question... is NumericUpDown available in the properties menu or should i code it at the back end where i enter the code ?
 
Back
Top