Results 1 to 6 of 6

Thread: Button background color

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    10

    Button background color

    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?

  2. #2
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    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:
    1. Button1.BackColor = Color.Red

    Wkr,

    sparrow1
    Last edited by sparrow1; Jun 1st, 2006 at 04:52 PM.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    10

    Re: Button background color

    VB2005
    I need to change the background color in runtime

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Button1.BackColor = Color.Red
    3.     End Sub

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #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

  6. #6
    Addicted Member
    Join Date
    Aug 2002
    Posts
    224

    Re: Button background color

    Hi,

    Add 3 Buttons to your Form

    VB Code:
    1. Private Sub Button1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown _
    2.   , Button2.MouseDown, Button3.MouseDown
    3.  
    4.         Dim b As Button = DirectCast(sender, Button)
    5.         For Each ctl As Control In Me.Controls
    6.             If TypeOf ctl Is Button Then
    7.                 DirectCast(ctl, Button).BackColor = System.Drawing.SystemColors.Control
    8.                 DirectCast(ctl, Button).UseVisualStyleBackColor = True
    9.             End If
    10.         Next ctl
    11.         b.BackColor = Color.Yellow
    12.  
    13.     End Sub

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