I am trying to get a toggle button effect (not just a color change) to
converted from VB6 to dotnet
it works find in vb6 but not in the conversion how come?
Vb6 code
form1 with conmmandbutton1
'Then it's a simple matter of toggling the button in its Click event
procedure. The following code changes the button's caption as well:
Private Sub Command1_Click()
Static Downstate As Long
Downstate = Not Downstate
If Downstate Then
Command1.Caption = "Option On"
Command1.BackColor = &HFF&
Command2.SetFocus
Else
Command1.Caption = "Option Off"
Command1.BackColor = &HFF00&
Command2.SetFocus
End If
Call SendMessageBynum(Command1.hwnd, BM_SETSTATE, Downstate, 0)
End Sub
module1
Public Const BM_SETSTATE = &HF3
Declare Function SendMessageBynum _
Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
dotnet code
form1 with conmmandbutton1
Option Strict Off
Option Explicit On
Friend Class Form1
Inherits System.Windows.Forms.Form
'Then it's a simple matter of toggling the button in its Click
event procedure. The following code changes the button's caption as
well:
Private Sub Command1_Click(ByVal eventSender As System.Object,
ByVal eventArgs As System.EventArgs) Handles Command1.Click
Static Downstate As Integer
Downstate = Not Downstate
If Downstate Then
Command1.Text = "Option On"
Command1.BackColor =
System.Drawing.ColorTranslator.FromOle(&HFF)
Command2.Focus()
Else
Command1.Text = "Option Off"
Command1.BackColor =
System.Drawing.ColorTranslator.FromOle(&HFF00)
Command2.Focus()
End If
Call SendMessageBynum(Command1.Handle.ToInt32,
BM_SETSTATE, Downstate, 0)
End Sub
End Class
Option Strict Off
Option Explicit On
Module Module1
Public Const BM_SETSTATE As Short = &HF3s
Declare Function SendMessageBynum Lib "user32" Alias
"SendMessageA"(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal
wParam As Integer, ByVal lParam As Integer) As Integer
End Module