Results 1 to 6 of 6

Thread: Button

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Posts
    14

    Question

    HI,

    I WANT TO KNOW HOW TO CHANGE THE BACK COLOR OF THE BUTTON AT RUN TIME.

    I AM CREATED BUTTON ARRAY WITH 5 BUTTONS.
    LIKE CMDSAVE(0),CMDSAVE(1),CMDSAVE(2),...CMDSAVE(5)

    WHEN I CLICK THE CMDSAVE(0) THIS BUTTON BACKGROUND COLOR SHOULD BE CHANGE INTO RED COLOR AND ALL OTHER BUTTONS BACK GROUND COLOR SHOULD BE WHITE.

    AND AFTER THIS I PRESSED THE CMDSAVE(1) THEN CMDSAVE(1) BUTTON BACKGROUND COLOR RED AND CMDSAVE(0) BACK COLOR WHITE
    AND ALL OTHER BUTTONS COLOR WHITE.

    WHEN EVER USER CLICKS A PARTICULAR BUTTON THAT BUTTON COLOR CHANGES TO RED AND REMAINING INTO WHITE.


    BYE.





  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Posts
    14

    Question

    HI,

    I WANT TO KNOW HOW TO CHANGE THE BACK COLOR OF THE BUTTON AT RUN TIME.

    I AM CREATED BUTTON ARRAY WITH 5 BUTTONS.
    LIKE CMDSAVE(0),CMDSAVE(1),CMDSAVE(2),...CMDSAVE(5)

    WHEN I CLICK THE CMDSAVE(0) THIS BUTTON BACKGROUND COLOR SHOULD BE CHANGE INTO RED COLOR AND ALL OTHER BUTTONS BACK GROUND COLOR SHOULD BE WHITE.

    AND AFTER THIS I PRESSED THE CMDSAVE(1) THEN CMDSAVE(1) BUTTON BACKGROUND COLOR RED AND CMDSAVE(0) BACK COLOR WHITE
    AND ALL OTHER BUTTONS COLOR WHITE.

    WHEN EVER USER CLICKS A PARTICULAR BUTTON THAT BUTTON COLOR CHANGES TO RED AND REMAINING INTO WHITE.


    BYE.

  3. #3
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Ok,
    Put this under the CommandSave_Click()
    Code:
    CommandSave.BackColor = &H000000FF&   'red
    CommandSave1.BackColor = &H00FFFFFF&  ' white
    CommandSave2.BackColor = &H00FFFFFF&  'white
    
    CommandSave1_Click()
    CommandSave1.BackColor = &H000000FF&   'red
    CommandSave.BackColor = &H00FFFFFF&  ' white
    CommandSave2.BackColor = &H00FFFFFF&  'white
    You also have to chage the "Style" of the Command buttons to Graphical by going into the properties and scrolling to "style"
    is this undertandable?
    I hope so.
    Gl,
    D!m
    Dim

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Location
    Posts
    14
    yah,
    i did same way,
    but it's very long code we want to write.
    i request u to any other method for to achieve same function.

    becasue everytime we want to change the color of one button and same time other button's color.

    bye

  5. #5
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    Well i guess you can use If Then statements...but that could take just as much code if not more.
    Code:
    If Command1.BackColor= Blah Then
       Command2.BackColor= Bla
       Command3.BackColor= Blah 
    Else
      Command1.BackColor=Blah
    End If
    I hope you get the idea...If you have 3 command buttons then it would take 3 If Then statents.
    So i would go with the previous post.

    Gl,
    D!m
    Dim

  6. #6
    Guest
    Another method is to loop through all of the Buttons.

    Code:
    Private Sub cmdSave_Click(Index As Integer)
    
        'If cmdSave(0) is presed
        If Index = 0 Then
        
            'Change cmdSave(0) Backcolor to Red
            cmdSave(0).BackColor = vbRed
            
            'Loop through the rest of the Controls in the Array and change their
            'Backcolor to white.
            For I = 1 To 5
                cmdSave(I).BackColor = vbWhite
            Next I
        
        End If
    
    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