M
mauro
hi ,
i am tryng to disable buttons in the meanwhile a long
operation is running ,
i found many posts on that , and
i am tryng to use OpennetCF ApplicationEx (Application2)
with IMessagefilter .
i found an example for disabling TextBoxes to receives inputs ,
and i am tryng to make the same behave to a button , result is that the
first click is correctly disabled , but when i click again , the button
is enabled again ....if someone could help me to correct my
code in the way that i can decide when start again enebling the button ,
it would be great .
the code :
i run the form2 with Application2.Run(New Form2)
Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu2 As System.Windows.Forms.MainMenu
Private custButton As clsButton
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CreateControls()
End Sub
Private Sub cusButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
MessageBox.Show(" a ")
End Sub
Private Sub CreateControls()
custButton = New clsButton(AddressOf Form_KeyDown)
custButton.Location = New Point(66, 229)
custButton.Size = New Size(72, 20)
Me.Controls.Add(custButton)
AddHandler custButton.Click, AddressOf cusButton_Click
AddHandler custButton.GotFocus, AddressOf Button_OnClick
Application2.AddMessageFilter(custButton)
End Sub
Private Sub Button_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim thisButton As clsButton = DirectCast(sender, clsButton)
With thisButton
.Capture = True
.HWnd = GetCapture()
.Capture = False
End With
End Sub
Sub Form_KeyDown(ByVal e As KeyEventArgs, _
ByVal lparam As Integer)
MessageBox.Show("KeyDown: " + e.KeyData.ToString())
End Sub
<DllImport("coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Function
End Class
Public Class clsButton
Inherits Button
Implements OpenNETCF.Windows.Forms.IMessageFilter
Private pHWnd As IntPtr
Private myfunc As MyKeyDownDelegate
Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
End Sub
Public Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) _
As Boolean Implements _
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
Try
If m.HWnd.Equals(pHWnd) Then
Select Case m.Msg
Case &H100
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Public Property HWnd() As IntPtr
Set(ByVal Value As IntPtr)
pHWnd = Value
End Set
Get
Return pHWnd
End Get
End Property
End Class
thank you
mauro
i am tryng to disable buttons in the meanwhile a long
operation is running ,
i found many posts on that , and
i am tryng to use OpennetCF ApplicationEx (Application2)
with IMessagefilter .
i found an example for disabling TextBoxes to receives inputs ,
and i am tryng to make the same behave to a button , result is that the
first click is correctly disabled , but when i click again , the button
is enabled again ....if someone could help me to correct my
code in the way that i can decide when start again enebling the button ,
it would be great .
the code :
i run the form2 with Application2.Run(New Form2)
Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu2 As System.Windows.Forms.MainMenu
Private custButton As clsButton
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CreateControls()
End Sub
Private Sub cusButton_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
MessageBox.Show(" a ")
End Sub
Private Sub CreateControls()
custButton = New clsButton(AddressOf Form_KeyDown)
custButton.Location = New Point(66, 229)
custButton.Size = New Size(72, 20)
Me.Controls.Add(custButton)
AddHandler custButton.Click, AddressOf cusButton_Click
AddHandler custButton.GotFocus, AddressOf Button_OnClick
Application2.AddMessageFilter(custButton)
End Sub
Private Sub Button_OnClick(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim thisButton As clsButton = DirectCast(sender, clsButton)
With thisButton
.Capture = True
.HWnd = GetCapture()
.Capture = False
End With
End Sub
Sub Form_KeyDown(ByVal e As KeyEventArgs, _
ByVal lparam As Integer)
MessageBox.Show("KeyDown: " + e.KeyData.ToString())
End Sub
<DllImport("coredll.dll")> _
Private Shared Function GetCapture() As IntPtr
End Function
End Class
Public Class clsButton
Inherits Button
Implements OpenNETCF.Windows.Forms.IMessageFilter
Private pHWnd As IntPtr
Private myfunc As MyKeyDownDelegate
Public Sub New(ByVal DelegateFunction As MyKeyDownDelegate)
myfunc = DelegateFunction
End Sub
Public Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) _
As Boolean Implements _
OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
Try
If m.HWnd.Equals(pHWnd) Then
Select Case m.Msg
Case &H100
myfunc.Invoke(New KeyEventArgs(m.WParam.ToInt32), _
m.LParam.ToInt32)
End Select
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Public Property HWnd() As IntPtr
Set(ByVal Value As IntPtr)
pHWnd = Value
End Set
Get
Return pHWnd
End Get
End Property
End Class
thank you
mauro