wilsoada
asked on
Simulate mouse click or event with another event (keydown event)
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.KeyEv entArgs) 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
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.KeyEv
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
ASKER
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Messa
&
Return MyBase.ProcessCmdKey(msg, keyData)
or give me some reference as to where I can learn what is going on here?