gopalhazel
asked on
how to fire textbox double click event on F2 press in vb.net
Hi,
I want to excute Textbox1's double click event on keyboard's F2 press.
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles Me.KeyUp
'Dim KeyCode As Short = e.KeyCode
'Dim Shift As Short = e.KeyData \ &H10000
Try
'Call gf_ProcessKey(KeyCode, Shift, True, Me)
If e.KeyCode = Keys.F2 Then
-------------how to call textbox1's double click event from here------- i want to make it generic i.e.
it should get executed depending upon me.activecontrol---------- ---------- ------
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
code for double click event:
Private Sub TextBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
Try
MonthCalendar1.Visible = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
I want to excute Textbox1's double click event on keyboard's F2 press.
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv
'Dim KeyCode As Short = e.KeyCode
'Dim Shift As Short = e.KeyData \ &H10000
Try
'Call gf_ProcessKey(KeyCode, Shift, True, Me)
If e.KeyCode = Keys.F2 Then
-------------how to call textbox1's double click event from here------- i want to make it generic i.e.
it should get executed depending upon me.activecontrol----------
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
code for double click event:
Private Sub TextBox1_DoubleClick(ByVal
Try
MonthCalendar1.Visible = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
ASKER
actually i want to do using sendmessage API , but it is not calling double click event
for e.g.
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Const WM_LBUTTONDBLCLK As Short = &H203S
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles Me.KeyUp
Try
If e.KeyCode = Keys.F2 Then
Call SendMessage(Me.ActiveContr ol.Handle, WM_LBUTTONDBLCLK, 0, 0)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
so what can be done??
for e.g.
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Const WM_LBUTTONDBLCLK As Short = &H203S
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv
Try
If e.KeyCode = Keys.F2 Then
Call SendMessage(Me.ActiveContr
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
so what can be done??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you for the help.
alternatively, i have used as,
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles Me.KeyUp
If e.KeyCode = Keys.F2 Then
Dim CntrName As String = Me.ActiveControl.Name()
CntrName = CntrName & "_DoubleClick"
Dim myType As Type = Me.GetType()
Dim m As MethodInfo = myType.GetMethod(CntrName, BindingFlags.NonPublic Or BindingFlags.Instance)
If IsNothing(m) Then Exit Sub
Dim Fargs = New Object(1) {}
Fargs(0) = Me
Fargs(1) = New System.EventArgs()
m.Invoke(Me, Fargs)
End If
End Sub
alternatively, i have used as,
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv
If e.KeyCode = Keys.F2 Then
Dim CntrName As String = Me.ActiveControl.Name()
CntrName = CntrName & "_DoubleClick"
Dim myType As Type = Me.GetType()
Dim m As MethodInfo = myType.GetMethod(CntrName,
If IsNothing(m) Then Exit Sub
Dim Fargs = New Object(1) {}
Fargs(0) = Me
Fargs(1) = New System.EventArgs()
m.Invoke(Me, Fargs)
End If
End Sub
Private Sub DoubleClickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Try
MonthCalendar1.Visible = True
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
e.g your double click nows look like:
Private Sub TextBox1_DoubleClick(ByVal
DoubleClickHandler(sender,
End Sub
do the same for the other handler.