Results 1 to 9 of 9

Thread: [RESOLVED] VB6 Button Backcolor

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Resolved [RESOLVED] VB6 Button Backcolor

    I am going nuts and I feel so stupid for not being able to figure this out!

    I have four buttons, A B C and D, and when you click on A, I want the backcolor of the button to change. Then when you click on B, I want A to change back to grey, and for B's backcolor to change. Could anyone help me out with this?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB6 Button Backcolor

    Welcome to the forms.

    What code do you have in your button clicks now?

    Are they stand alone buttons or in an array?

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: VB6 Button Backcolor

    Add one command button
    set the STYLE = Graphical

    now copy the button and paste it 3 times... YES, you want a control array
    VB Code:
    1. Private Sub Command1_Click(Index As Integer)
    2.     For x = 0 To Command1.UBound
    3.         If x = Index Then
    4.             Command1(x).BackColor = &HFF& 'Red
    5.         Else
    6.             Command1(x).BackColor = &H8000000F 'Button Face
    7.         End If
    8.     Next
    9. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: VB6 Button Backcolor

    These are stand alone buttons... I cannot use a control array...

  5. #5
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: VB6 Button Backcolor

    ok.. fancy way:

    VB Code:
    1. Private Sub Command1_Click()
    2.     SetBGColor Command1
    3. End Sub
    4.  
    5. Private Sub Command2_Click()
    6.     SetBGColor Command2
    7. End Sub
    8.  
    9. Private Sub Command3_Click()
    10.     SetBGColor Command3
    11. End Sub
    12.  
    13. Private Sub Command4_Click()
    14.     SetBGColor Command4
    15. End Sub
    16.  
    17. Private Sub SetBGColor(btn As CommandButton)
    18.     Dim ctl As Control
    19.     btn.BackColor = &HFF
    20.     For Each ctl In Me.Controls
    21.         If TypeOf ctl Is CommandButton Then
    22.             If ctl <> btn Then
    23.                 ctl.BackColor = &H8000000F
    24.             End If
    25.         End If
    26.     Next
    27.                
    28. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: VB6 Button Backcolor

    Thats VB.NET... I'm looking for VB 6

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: VB6 Button Backcolor

    look again. thats VB6
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    30

    Re: VB6 Button Backcolor

    Very sorry static. Thank you so much.

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: VB6 Button Backcolor

    No problem!!

    now that its saolved.. please go to thread tools and click mark thread resolved

    Thanks!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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