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

Button depressed without clicking

Status
Not open for further replies.

Disferente

Programmer
Jun 23, 2008
112
US
Is there any way of making a command button look like it is pressed down without using the mouse or any key presses?
 

And why would you want it?

If you explain it better, with the reason for it - it may be some other way to accomplish it....

Have fun.

---- Andy
 
Sure ... but the method used may differ depending on what exactly you are trying to achieve
 
All I want is the visual effect of the button being pressed down. I know I can use a picture for it, but was hoping there to be another way.
 

That's nice, but I (we) still don't know why you want to change default windows behavior in your GUI? If you clue us in on the reason I am sure people will help you…..

Have fun.

---- Andy
 
>the visual effect of the button being pressed down

Permanently pressed down? Briefly pressed down? Appearing as if it has focus? Generating any events?
 
Becoming briefly pressed down. Event's does not matter, would not use them.
 
Might be that the OP wants to simulate the steps of a ghost figure, tip-toeing across the window.

Or could it be something that appears like player piano keys, tripping along with tin pan tunes.

Maybe .....

Oh, well! Seems like we'll NEVER be clued in.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Why not use a check box as a Button?

1. Add a check box to the form (Name: Check1).
2. Change it's Style Property to 1-Graphic
3. Add the following code:
Code:
[COLOR=blue]
Private Sub Check1_KeyDown(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyReturn) Then
        Check1.Value = vbChecked
    End If
End Sub

Private Sub Check1_KeyUp(KeyCode As Integer, Shift As Integer)
    If (KeyCode = vbKeyReturn) Then
        Check4.Value = vbUnchecked
    End If
End Sub
[/color]

This will cause it to act like a button being pressed when the Enter/Return key is used on it.

In order to show it continuously as pressed, just assign
Check1.Value = vbChecked
 
This line:

Check4.Value = vbUnchecked

needs to read

Check1.Value = vbUnchecked
 

Code:
Private Sub Command1_Click()
 Dim delay As Double
 delay = Timer()
 Me.cmdBtn.SpecialEffect = 3
  Pause (0.5)
  Me.cmdBtn.SpecialEffect = 1
End Sub

Sub Pause(ByVal nSecond As Single)
Dim t0 As Single
Dim dummy As Integer
     t0 = Timer
        Do While Timer - t0 < nSecond
           dummy = DoEvents()
           If Timer < t0 Then
              t0 = t0 - 24 * 60 * 60 ' or t0 = t0 - 86400
           End If
        Loop
End Sub
[code]
 

>.SpecialEffect

MajP, could it be that your code is from VBA, and not VB6?
 
Yeah I ran it in vba using MSforms control, I did not have vb on the computer I was using. Bad assumption on my part. I assumed that property was common to both.
 
Mind you, if you know that you have Office on the target machine(s) then there is no reason why you cannot use a button from the Forms 2 library, and thus use SpecialEffect
 
Having said that, I should point out that sunken effect applied to a graphical checkbox/option button or to a Forms 2 toggle button does not normally look the same as a VB command button being depressed. Which is one of the reasons I wanted to know what the OP was hoping to achieve.
 
Were either of the Checkbox or Forms 2 solutions good enough for your purpose, Disferente?
 
It looks a bit different, but it's nothing I can't live with. Thank you all for your help.
 

I am convinced that Disferente works on top secret government project in some undisclosed location similar to witness protection program. And if he/she would tell us about it, than he/she would have to ……. You know… And I LOVE to continue on living. :)

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top