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?
 
Form. Two buttons.
Code:
[blue]Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const BM_SETSTATE = &HF3

Private Sub Command1_Click()
    Command2.SetFocus ' If we want the control outlined and to have the focus rectangle for the full 'pressed' effect
    SendMessage Command2.hwnd, BM_SETSTATE, True, 0& ' Down - which is how a COmmand Button is highlighted
    Sleep 500 ' Brief pause so we can see button is down
    SendMessage Command2.hwnd, BM_SETSTATE, 0&, 0& ' Up - remove highlighting
    Command1.SetFocus
End Sub
[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top