We help IT Professionals succeed at work.

How can I setup my menu strip to act in the following ways (VB.NET)

Depending on the value of a boolean variable, I want the menu item to act in the following ways:

If the value is false, I want the menu to act like it would normally.

If the value is true, I want to force the user to have to click on the main menu to display the menu list. I do not want the user to be able to hover their mouse over a main menu to see sub menu, even if a sub menu list is already displayed.

Here is the background reason why :

File <=== Main Menu
- Open <==== Sub menu
- Save <==== Sub menu

Here's the background information and reason why I need it to act this way

One of my menus have a very long list of sub menus. The user has to go through these lists from top to bottom in order. All sub menus open up a form. For example, I'll say the beginning of the menus is "A" and the last menu option is "Z".

When the user clicks on sub menu "A", a form appears.
When they close the form, the menu option they most recently clicked on is displayed with the most recent sub menu a different background color. This works great.

My problem is caused by three things:

1. my MDI style application has the minimized, restore, close buttons are located at the top left (not top right as normal).

2. My menu strip is on the top and is horizontal (left to right). The menu lasts two rows so when the user closes a form, they can't move anywhere without hovering the mouse over a different main menu.

3. When the user closes the form, the sub menu is displayed properly but when the user moves the mouse over a different main menu, that sub menu is displayed (making the most recently clicked on one disappear). I'm trying to prevent this.
Watch Question


This is what I'm trying to accomplish.

Lets say you have these two file Menus.

File              Edit
- Open         - Undo
- Save          - Redo
...                  ...

By design, if you click on [File], the file menu displays. If you move the mouse over to the [Edit] field, the Edit menu displays without you having to click on [Edit]. I want to be able to turn on or off this function/ability. I want to be able to force the user to click on [file] to see the file menu and then click on [edit] to see the edit menu.


Thank you for your help. I greatly appreciate it. I still have not yet received any experts comments on this question. I never thought this question would be so hard to accomplish.


It doesn't seem like this question is going to get a response from the Experts.

I've somewhat came up with a work around to this problem but it doesn't accomplish what I want to do.

It is setup so that when the user closes a child form that last menu clicked is displayed and the mouse would go exactly where it was located when it opened up the child form.

I believe this will be the solution to my problem unless someone can come up with a better suggestion.
Hello, JohnnyBCJ,

This does seem like a tough nut to crack.  

I suppose that possible solution would be to create your own version of a MenuStrip so that you could control this aspect of its behaviour.  Offhand, I think that will be quite a lot of work, so the requirement would have to be important enough to justify it.

The only other thing that I have been able to come up with involves a timer -- rather cludgey.   The snippet shows the code in a form that has a Button, a Timer with interval set to 10 ms and a MenuStrip with four main menu items (Item1ToolStripMenuItem, Item2ToolStripMenuItem, etc.)  The Button controls a boolean flag that determines how the menus respond to the MouseHover event.  I REALLY don't like this "solution", but since nobody is offering anything better... well there it is, eh.


Public Class Form1

    Private mbooHoverEnabled As Boolean = True

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Timer1.Enabled = Not mbooHoverEnabled
        Me.Button1.Text = "Disable ""Hover"" response"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mbooHoverEnabled = Not mbooHoverEnabled
        If (mbooHoverEnabled) Then
            Me.Button1.Text = "Disable ""Hover"" response"
            Me.Button1.Text = "Enable ""Hover"" response"
        End If
        Me.Timer1.Enabled = Not mbooHoverEnabled
    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    End Sub
End Class

Open in new window

Hello omegaomega

Indeed, this problem isn't an easy one. I know this problem can be solved, it's just a matter of figuring it out and putting in the time to do so.

I thought it would be a simple overrides statement. Maybe in a perfect world. I guess not. haha.

I can follow your logic but unfortunately I will not be using it in my project. As you stated, When I get the time I might attempt to create my own version of a menu strip to control the behavior I want. I have more important things to work on at the moment.

I greatly appreciate your input! It would be interesting to figure out how many people read my question and decided it'd be too much work to either try to explain whats needed or if the question was too technical.

Thank you again!!


I'm aware that EE may be having problems with the Accepting a comment as an answer so I am going to check on this in a couple of days so I can give you some points for your thoughts. Thanks again!

Hello, JohnnyBCJ,

Yes, I also tried looking for some "Override" either in a custom (MenuStrip or a custom ToolStripMenuItem) that would do the trick.  I even investigated overriding WndProc, but couldn't find a consistent combination of Window messages that could be used.

I too would NOT use the "solution" I illustrated.  So unless you get a better answer from someone else,  I suggest that you request the points be refunded.  (I'm not actually here for the points, anyway.)



I also tried the overriding WndProc as I'm already doing that to accomplish other things in my program. It seems like we're both in the same boat when it comes to this problem. I figured out of all the VB.Net programs made that this problem would have already been solved. It doesn't seem like it's "that hard" of a thing to accomplish.

I like giving credit where credit is due. Out of all the people who looked at my problem, you're the only one that gave me a suggestion. That deserves points in my book.