simulate click in menustrip

dg78

Member
Joined
Jul 12, 2006
Messages
10
Programming Experience
Beginner
Hi,

In WinForm 2.0 (VB), i have a menustrip and many toolstripmenuitems.
Suppose that i have menu0, menu1, .. in the menustrip.
Under menu1, i have menu10, menu11, .. and under menu11, i have menu110, menu111, ...
The user click on menu111 then I hide the menustrip and i do the
appropriate work for menu111.
When this work finished, i want the menustrip to be open on menu111
without the user click on menu1 and menu11.
How can I do that ?
select then sendkey ? windows messages ? or easily in VS 2.0 ?

Thanks in advance,

Dominique
 
Thanks for your quick answer.

After reading the thread that you indicate, I think (but I can mistake) that it is not the same problem.
I don't want dismiss the menustrip but after the work, I want re-activate the menustrip in the same state before the last click (the last click was menu111 in my sample, so I want to display and open menu1 and menu 11, put the cursor on menu111 and wait here).

Already I tried PerformClick and it didn't solve my problem.

Cheers,

Dominique
 
Ah, i see. So you actually want to do the complete reverse of what was dicussed in that thread? Re-open the menu you just clicked? is that right?
 
dg78, yes, that only hides it. Here is one suggestion to re-open the menu as it were when item was clicked. The key is that all OwnerItems all the way down to the MenuStrip control itself have to be displayed with the ShowDropDown method, and this also have to happen in absolute order from root and up to the current menuitem (else they appear at strange places). The method:
VB.NET:
Sub openmenu(ByVal tsmi As ToolStripMenuItem)
  Dim l As New List(Of ToolStripItem)
  Dim tsiOwner As ToolStripItem = tsmi.OwnerItem
  Do Until tsiOwner Is Nothing
    l.Insert(0, tsiOwner)
    tsiOwner = tsiOwner.OwnerItem
  Loop
  For Each tsiOwner In l
    DirectCast(tsiOwner, ToolStripMenuItem).ShowDropDown()
  Next
End Sub
Example of usage, (does also get the cursor location and sets it again):
VB.NET:
Private Sub Submain221ToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Submain221ToolStripMenuItem.Click
  [SIZE=2][COLOR=#0000ff][COLOR=black]Dim[/COLOR][/COLOR][/SIZE][COLOR=black][SIZE=2] tsmi [/SIZE][SIZE=2]As[/SIZE][SIZE=2] ToolStripMenuItem = [/SIZE][SIZE=2]DirectCast[/SIZE][/COLOR][SIZE=2][COLOR=black](sender, ToolStripMenuItem)[/COLOR]
[/SIZE][COLOR=black][SIZE=2]  Dim[/SIZE][SIZE=2] loc [/SIZE][SIZE=2]As[/SIZE][/COLOR][SIZE=2][COLOR=black] Point = Windows.Forms.Cursor.Position[/COLOR]
[/SIZE][SIZE=2][COLOR=black]  'do something here ...[/COLOR]
[/SIZE][SIZE=2][COLOR=black]  openmenu(tsmi)[/COLOR]
[COLOR=black]  Windows.Forms.Cursor.Position = loc[/COLOR]
[COLOR=black]  tsmi.Select()[/COLOR]
[/SIZE][SIZE=2][/SIZE]End Sub
 
Back
Top