Solved

Simulate mouse click or event with another event (keydown event)

Posted on 2006-11-30
3
399 Views
Last Modified: 2007-11-27
My question deals with a general idea but I also have a specific issue to be dealt with including the problem. The idea is how to simulate events that happen when the user is using an application with other events. Here is my situation I have a treeview with the labeledit set to true. Seems the only way to edit a label is to select a node and click the mouse once. This causes the treeview to highlight the node text and make it editable all without calling mouse click events or anything it just "magically" happens. My question is how to take something like a keydown event (for instance the user pushes F2) and make it simulate what the treeview seems to know to do automatically with the mysterious mouse click that doesn't have any code behind it!!!!!!!!!! Going crazy trying to find good NET coding help this is for VS2005 visual basic only windows application.
0
Comment
Question by:wilsoada
[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
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18049703
"Seems the only way to edit a label is to select a node and click the mouse once."

Use the BeginEdit() method of the TreeNode you want to edit.

Something like...

Public Class Form1

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.F2 Then
            Dim tn As TreeNode = TreeView1.SelectedNode
            If Not IsNothing(tn) Then
                tn.BeginEdit()
            End If
            Exit Function
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

End Class
0
 

Author Comment

by:wilsoada
ID: 18049747
That is pure genius and exactly what I was looking for. Can you explain:

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
 &
Return MyBase.ProcessCmdKey(msg, keyData)

or give me some reference as to where I can learn what is going on here?


0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18049802
See:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.processcmdkey(VS.80).aspx

You could also set the KeyPreview() property of the Form to True and handle the KeyDown() event:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
    End Sub

    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 tn As TreeNode = TreeView1.SelectedNode
            If Not IsNothing(tn) Then
                tn.BeginEdit()
            End If
        End If
    End Sub

End Class
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System.net.Sockets Error 5 40
Crystal reports login after closing form 3 35
VB.NET Inline If statement 4 41
VB.net Code to make a TaskPane float in Excel Add-in 2 25
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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