Re: Button background color
Quote:
Originally Posted by mikebain
I am trying to highlight the background color of a button when it is pressed and can do this by the following:
cmd_low.BackColor = Color.Yellow
but i need to change it back to the default button color when another button is pressed (buttonface). any ideas?
Hi,
Is it VB.Net 2003 or 2005!
There are some buttons to let you make a selection.
Any way It's the same for 2003 and 2005
Try this;
VB Code:
Button1.BackColor = Color.Red
Wkr,
sparrow1
Re: Button background color
VB2005
I need to change the background color in runtime
Re: Button background color
Quote:
Originally Posted by mikebain
VB2005
I need to change the background color in runtime
It is just the same;
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.BackColor = Color.Red
End Sub
Wkr,
sparrow1
1 Attachment(s)
Re: Button background color
So basically what you're trying to do is create RadioButton functionality with standard Buttons, correct? If so you would be much better off actually using RadioButton controls. They have an Appearance property that you can set to Button and they will look exactly like a regular Button except that they stay depressed when you click them. When you then click another RadioButton the previous one will popup again. The depressed state corresponds to the Checked property being True. If you want to add the extra visual cue of colour you can then just do this:
VB Code:
Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged, _
RadioButton2.CheckedChanged, _
RadioButton1.CheckedChanged
Dim rb As RadioButton = DirectCast(sender, RadioButton)
If rb.Checked Then
rb.BackColor = Color.Yellow
Else
rb.BackColor = SystemColors.Control
End If
End Sub
Re: Button background color
Hi,
Add 3 Buttons to your Form
VB Code:
Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown _
, Button2.MouseDown, Button3.MouseDown
Dim b As Button = DirectCast(sender, Button)
For Each ctl As Control In Me.Controls
If TypeOf ctl Is Button Then
DirectCast(ctl, Button).BackColor = System.Drawing.SystemColors.Control
DirectCast(ctl, Button).UseVisualStyleBackColor = True
End If
Next ctl
b.BackColor = Color.Yellow
End Sub