Hide a child form from the parents "Window" menu

Posted on 2009-04-24
Last Modified: 2013-11-26

This might be a stupid question but I can't figure it out my self.

I have a VB net 2005 app with an MDI parent which has been added to the project(Including menu structure)
It has a "Window" menu in which I can select Cascade etc. This "Window" menu also contains a list of the child windows that are open.

Now I would like for one of my child windows not to have an entry in the "Window" menu.

How do i do that?

Thanks in advance
Question by:liversen
    LVL 1

    Expert Comment

    This "Window" menu that you speak of, Is this a contextmenu that you have added to the project?  Or are you refering to the built in context menu that opens when you right click on the form's titlebar?
    LVL 1

    Author Comment

    It is just a mdi form I added to the project using Add New Item and selecting mdiForm
    It then comes with its own context menu that has one item called Windows.
    It contains by default:
    New Window
    Tile Vertical
    Tile Horizontal
    Close All
    Arrange Icons

    I can not find any code that adds the <MDI CHILD X NAME> to the menu, It's kind of just happening

    and I need to make sure that e.g. <MDI CHILD 2 NAME> is not shown in the list.

    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    The List is populated automatically when you set the MdiWindowListItem() Property of the Main Menu:

    In the Image below, you can see the Main Menu (MenuStrip) is selected in the area below the Form.  Then, off to the Right, you can see the MdiWindowListItem() Property is set to WindowsMenu entry.  ("WindowsMenu" is the NAME of the Windows menu in the MenuStrip.  It can be named anything you want and doesn't have to the "Windows" as the Text.)

    You can't change the default behavior when using this approach.  If you want a custom menu then you would need to dynamically populate a menu item with the currently open child forms (only the ones that YOU want) each time is is invoked.

    Here is the setting:
    LVL 1

    Accepted Solution

    I think you are looking for a code example of how to exclude the menu item from showing for a certain child window.  Here is an example using the "DropDownOpening" event of the "WindowsMenu"

        Private Sub WindowsMenu_DropDownOpening(ByVal sender As Object, ByVal e As System.EventArgs) Handles WindowsMenu.DropDownOpening
            'Loop through each menu item for the WindowsMenu
            For Each menuItem As ToolStripItem In WindowsMenu.DropDownItems
                'Don't show menu item for child window with caption...
                If menuItem.Text.Contains("Window 2") Then
                    menuItem.Visible = False
                End If
        End Sub

    Open in new window

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Nice gearboxpc...we can only make decisions based on the Text of the MenuItem itself though.  We don't have any knowledge of the TYPE of the Form that the MenuItem points to...and for some apps that change the Caption of the form this might not be enough.
    LVL 1

    Expert Comment

    Thanks ~ Idle_Mind...  If you re-read the question from liversen and then check my comment / solution... you will see it does just what liversen asked for.  I am trying to keep it simple and stick to the question.  :)
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    I didn't say your solution doesn't do what the author asked for.  =(

    Have I somehow strayed off question?  =\

    I'm merely stating that it would only work if the caption of the form is static or somehow predictable...  =)
    (not always the case)
    LVL 1

    Author Closing Comment

    I'm choosing to go for the solution by gearboxpc because it is simple and it does what I need. In my case the form does not change name/caption so I can use the simple solution.
    On the other hand I can see Idle_Mind's point about solving it by populating the menu all manually.
    Thanks to both of you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now