Results 1 to 6 of 6

Thread: Button background color

Threaded View

  1. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Private Sub RadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged, _
    2.                                                                                                            RadioButton2.CheckedChanged, _
    3.                                                                                                            RadioButton1.CheckedChanged
    4.     Dim rb As RadioButton = DirectCast(sender, RadioButton)
    5.  
    6.     If rb.Checked Then
    7.         rb.BackColor = Color.Yellow
    8.     Else
    9.         rb.BackColor = SystemColors.Control
    10.     End If
    11. End Sub
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width