Skip to content

Visual Basic visibility of form objects

dc

Asked Jun 5, 2015, 12:54 PM EDTSolved
Share
LinkedInX

In a VB.NET 2008 desktop application, I need to add some initial selections with a corresponding button to the 'main' form, before any of the normal processing is allowed to occur. Thus due to that fact, I have the following questions to ask:

1. This application is using a System.Windows.Forms.MainMenu and I would like the 'File' option to not display until the 'new' button is clicked? If this is possible, would you showe me the code for this to occur?
2. If option #1 is not possible, is there a way to make System.Windows.Forms.MainMenu not display until the the 'new' button is clicked? If this is possible, would you show me the code for this to occur?
3. In this application there is code that adds menu items with logic like,
   "  MainMenu1.MenuItems(0).MenuItems.Add("New Item", New EventHandler(AddressOf ClickHandler))
      MainMenu1.MenuItems(0).MenuItems.Add("-") ".

     Is there a way to modify the order of list of menuitems after the menu items have already been created? Would I need to delete the menuitems at that point and create the menuitems again? Thus would you show me the code for this option and/or let me know if this option is not possible?
 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Manoj Bhoir
    ✓ Accepted answer0
    Hi,
     
    Instead of using  System.Windows.Forms.MainMenu you can use System.Windows.Forms.MenuStrip. Just Drag and drop this control from toolbox and it's easy to use.
     
    To enable File menu on New button click you can use this code :
     
    C#
    private void Form1_Load(object sender, EventArgs e)
            {
                fileToolStripMenuItem.Enabled = false;
            }
     private void buttonNew_Click(object sender, EventArgs e)
            {
                fileToolStripMenuItem.Enabled = true;
            }
     
    Also you can rearrange the menu's using Menu Item Collection Editor.
     
    If you want to do it programatically :
     
    For example, to add a menu item in the first position:
    Code
    menuStrip.Items.Insert(0, new ToolStripMenuItem { Text = "Sample" });
    0