VB6 to dotnet question

  • Thread starter Thread starter Wagon
  • Start date Start date
W

Wagon

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
 
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

This Declare statement isn't correct for VB.NET. Long should be
replaced by Integer (or IntPtr where it represents handles and
pointers).


Mattias
 
Thanks for your response. If you look at the original posting I had
already done (i posted both the VB^ and dotnet code) so I must be
doing something else wrong. I appreciate any advice you could give.

Thanks


This Declare statement isn't correct for VB.NET. Long should be
replaced by Integer (or IntPtr where it represents handles and
pointers).


Mattias


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
 
I am trying to get a toggle button effect (not just a color change) to
converted from VB6 to dotnet

What about using a CheckBox with its Appearance set to 'Button'? You
wouldn't need the API then. The new Toolstrip Buttons have a 'Pressed'
(or it may be 'Pushed') style so that might be an option?
 
I had already thought about what you said but using this method allows
me to change the "state" of the button without actully triggerring an
event (ie the _click event) while using the checkbox means any change
in state will trigger events and require adding public variables to
block an event from occuring

I am not as familiar with the Toolstrip button but I suspect it too
will triger an event when it state is changed.
 
Thanks for your response. If you look at the original posting I had
already done (i posted both the VB^ and dotnet code) so I must be
doing something else wrong.

My appologies, I guess I didn't scroll down all the way.


Mattias
 
Back
Top