Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Color & Caption of Command Button

Status
Not open for further replies.

kristi1023

Programmer
Jan 8, 2002
59
US
Can I change the color and caption of a command button based upon how many times it is clicked?

For instance:
One Click = White /Caption = 1
Two Clicks = Yellow /Caption = 2
Three Clicks = Orange/Caption = 3
Four Clicks = Red /Caption = 4
Five Clicks = Begin Loop at One Click

Any ideas would be great. Thanks..Kristi..
 
Thank you for that link, Mark, it has many procedures that I will definitley use.

My main focus, however, isn't color coding the button (although it would be nice), I want to be able to update the caption on the button based upon the clicking sequence in my initial post. Can this be done with the On Click event? If so, how would I keep track of the number of clicks and format the caption correctly?

Thanks..Kristi..
 
Define a Static variable in your Click event procedure.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
use a label and make it raised. It will look like a button
Code:
Private Sub Label13_Click()
  ' set the special effect to raised to look like a command button
  Select Case Label13.Caption
  Case "1"
    Label13.Caption = "2"
    Label13.BackColor = vbYellow
 Case "2"
    Label13.Caption = "3"
    Label13.BackColor = 4227327
 Case "3"
    Label13.Caption = "4"
    Label13.BackColor = vbRed
 Case Else
    Label13.Caption = "1"
    Label13.BackColor = vbWhite
 End Select
End Sub
No need to track the clicks
 
Also you can add this to the beginning of the code. It change s the label to sunken and then back to raised. Gives the affect of click a command button.

Dim delay As Long
delay = Timer
Label13.SpecialEffect = 2
Me.Repaint
Do Until Timer > delay + 0.2
Loop
Label13.SpecialEffect = 1
 
Hello Kristi
The code below does what you ask and its test! I used a command button titled cmdTest and put the code under the click event of that button
'
Private Sub cmdTest_Click()
Static Count As Integer
Count = Count + 1
'
Select Case Count
Case 1
cmdTest.Caption = 1
Case 2
cmdTest.Caption = 2
Case 3
cmdTest.Caption = 3
Case 4
cmdTest.Caption = 4
Case 5
'Reset Count
Count = 1
cmdTest.Caption = 1
End Select
End Sub
'
Regards
Mark
 
How are ya kristi1023 . . .

In parallel with [blue]MajP[/blue]:
Code:
[blue]  Dim idx As Integer
  
  idx = Val(Me!LabelName.Caption)
  Me!LableName.Caption = Choose(idx, "2", "3", "4", "1")
  Me!LableName.BackColor = Choose(idx, vbYellow, 4227327, vbRed, vbehite)[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thank you all for your help. If I use the command button method, I can't use color coding..right? Also, I couldn't get the color coding to work with the label method and get a data type mismatch on TheAceman1's loc Me!LableName.Caption = Choose(idx, "2", "3", "4", "1").

If I place a command button or label next to every skill, 50 skills for instance, would I have to add the code to the on click event of every command button or label?

Thanks..Kristi..
 
I got the color coding to work. So simple, I had to change backstyle from transparent to normal. :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top