Toggles

Turkey_II
01-25-2005, 01:27 PM
I can't toggle normal command buttons. Can you tell me how?

OnErr0r
01-25-2005, 01:38 PM
If you use a graphical style checkbox, it looks almost exactly like a command button, and is "sticky", meaning it will stay down when pressed.

noi_max
01-25-2005, 02:12 PM
Perhaps a less elegant way ;)

Private Sub Form_Load()

Command1.Caption = "Off"

End Sub

Private Sub Command1_Click()

Static Switch As Boolean

Switch = Not (Switch)

If Switch = True Then

Command1.Caption = "On"
'Do your "On" switch code here

Else

Command1.Caption = "Off"
'Do your "Off" switch code here

End If

End Sub

akamikeym
01-26-2005, 05:53 AM
Here is the code you want I think (although it does use the API). Just make a form and add a command button 'Command1' and paste this code:


'API call to send a message to a window or component
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

'Constant to show we are sending a button
'State message
Private Const BM_SETSTATE = &HF3

'Is our button Down?
Private Toggle As Boolean

Private Sub Command1_Click()
If Toggle = False Then
'Send message to make our button down
SendMessage Command1.hwnd, BM_SETSTATE, 1&, O&
Toggle = True
Else
'Send message to make our button up
SendMessage Command1.hwnd, BM_SETSTATE, 0&, O&
Toggle = False
End If
End Sub


Hope this helps :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum