disabling the mainmenu in a form

Hi

Does anyone know how to make the main menu in a form non responsive.

I have this function which expects the user to pick a point on a pictureBox in the form with the mouse. Until this happens i want to stop the user selecting anything else on the form. The only thing he can selected at the moment is in the main menu that's why i want to make it non responsive for a while.

Any ideas how to make this work.

Much appreciate it.

george



Answer this question

disabling the mainmenu in a form

  • Matt Bell

    Hi again

    Thanks for the help guys. Unfortunately MenuItem does not have a Tag, only Forms and Controls seem to have one (working with C++ under .NET 2003) and i guess menu items are not controls.

    Never the less i got the picture which way to go to sort this one out.

    Thanks once more

    george


  • niallhannon

    Couldn't he just override WndProc and only allow messages to picturebox.handle to be passed

     

    EDIT: Ok, I think the best would be to use a HashTable and store each menuitems enabled state. Disable them all, and when done refer to the hash table to see if they should be enabled or disabled...



  • ar_pad

    WndProc() won't work, there's one for each individual control. I'd use the MenuItem.Tag property to save the Enabled state.


  • Cory6132

    Thanks for the replies guys.

    The 'Menu' class does not have an 'Enabled' member.

    About the 'MenuStrip' i can't find it and the PictureBox->Capture still allows for menu items to be selected. I am using C++ under .NET 2003.

    Am i missing something

    george

  • R.Tutus

    Yes, the menu items do have an Enabled member but i would prefer not to use that because a lot of them are not always enabled and will have to keep track of their original state. I would have preferred to just disable the MainMenu all together and re-enable it accordingly.

    But it looks like i might have to work with the menu items after all.

    Just in case, does anyone know if it would be possible to restrict the mouse from exiting the pictureBox In this way the user wouldn't be able to select anything else. Is this a good idea

    george


  • David Avsajanishvili

    Hrmm. I'm not sure but menu.Enabled = false should work Sorry, got no time to check it out now...

  • Philip Quirke

    Yes, MenuStrip.Enabled works. You also might want to turn on mouse capture (PictureBox.Capture = true) to redirect all mouse input to the picture box. Modal operations like this are usually a lot of trouble, considering just setting a flag that indicates "the next MouseDown on the picture box is to select a point".


  • xRuntime

    Check again, MenuItem.Tag works when I try it...


  • DC Ross

    Hmm, that could work. Use a timer and make sure the mouse is always inside the picturebox. If you use a timer then the mouse won't be stuck in the picturebox if the program crashes.

  • zybernau

    Yep, you're missing the .NET 2.0 MenuStrip class. The .NET 1.x MainMenu class doesn't have a Enabled property. The menu items however have one. This code seemed to work as intended:

    private void button1_Click(object sender, EventArgs e) {
    foreach (MenuItem item in mainMenu1.MenuItems)
    item.Enabled = !item.Enabled;
    }



  • disabling the mainmenu in a form