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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Button 3

Status
Not open for further replies.

serino

Programmer
Feb 13, 2003
107
0
16
US
HI,

I have a button problem here. Is there a way to have a button show it is pressed when it is clicked on.

Any assistance appreciated.

Serino

Enjoy life......
 
Serino,


Depending on what you need in your application you can have the click of button set it's caption so it becomes the word Clicked or you could disable the button so it would become grayed out.

The second option would mean there would need to be something set up so if you needed it the button could be enabled and clicked once again.


HTH,


Steve
 
Steve,

Thanks for the reply.

I need the button to be sunken (instead of Raised) and change its color to light grey when the button pressed on.

How would I do this?

Serino

Enjoy life......


 
This sounds like a great idea! If anyone figures this out, I'd like to know the answer as well.

Russ
 
Serino,

Try using a toggle button instead of a command button.
 
Basically, your code would look something like this for the On Click :

Private Sub Toggle7_Click()
If Toggle7.Caption = "Not Clicked" Then
Toggle7.Caption = "clicked"
Toggle7.ForeColor = vbRed
ElseIf Toggle7.Caption = "Clicked" Then
Toggle7.Caption = "Not clicked"
Toggle7.ForeColor = vbBlack
End If

End Sub
 
Steve,

Thanks, that worked great!

How would you have the toggle Switch change the BackColor when depressed.

I tried removing ForeColor from the code below and adding BackColor but nothing happened.

Private Sub Toggle7_Click()
If Toggle7.Caption = "Not Clicked" Then
Toggle7.Caption = "clicked"
Toggle7.BackColor = vbRed
ElseIf Toggle7.Caption = "Clicked" Then
Toggle7.Caption = "Not clicked"
Toggle7.BackColor = vbBlack
End If
End Sub


Serino


Enjoy Life.....
 
Serino,

In the case of the Access command buttons the background color property is not exposed. I know in VB there is a graphics mode for the buttons that will allow you to change the back ground color.

The only work around that I know of is to set a rectangle with the color and raised style the overlay it with a transparent button so the on click event can be used.

HTH,

Steve
 
Steve,

Thanks again, I will play around with that idea.

Serino


Enjoy Life........
 
Hi!

Have you tried using a label? With a label you can set the specialeffect sunken/raised and backcolor programmaticaly, and it does also have a on click event. Something like this might be used:

[tt]If Me!lblTst.SpecialEffect=1 Then
Me!lblTst.SpecialEffect=2
Me!lblTst.BackColor = 15263976
Else
Me!lblTst.SpecialEffect=1
Me!lblTst.BackColor = -2147483633
End If[/tt]

In addition to your other code.

Roy-Vidar
 
Roy-Vidar,


This is just what I was looking for. Thanks!

Instead of using the "On Click" I used "GotFocus"and"LostFocus" and it worked just fine.

Serino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top