Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to fire textbox double click event on F2 press in vb.net

Posted on 2010-11-26
4
Medium Priority
?
1,111 Views
Last Modified: 2012-05-10
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.KeyEventArgs) 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
0
Comment
Question by:gopalhazel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 34221068
Just implement a private method to be called by key and double click event

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 sender As Object, ByVal e As System.EventArgs) Handles TextBox1.DoubleClick
       DoubleClickHandler(sender, e)
 End Sub

do the same for the other handler.
0
 

Author Comment

by:gopalhazel
ID: 34221432
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.KeyEventArgs) Handles Me.KeyUp
            Try
                If e.KeyCode = Keys.F2 Then
                     Call SendMessage(Me.ActiveControl.Handle, WM_LBUTTONDBLCLK, 0, 0)
              End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

so what can be done??
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 34223299
My posted solution is generic enough, your key up method will be: (notice Me.TextBox1 as the sender)
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
                  DoubleClickHandler(Me.TextBox1, null)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

You do not require a SendMessage call for implementing a solution for your question.
0
 

Author Comment

by:gopalhazel
ID: 34227857
thank you for the help.

alternatively, i have used as,

 Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) 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
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question