Results 1 to 6 of 6

Thread: menus - im losing it!!!

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    menus - im losing it!!!

    Hi, i think im gonna crack up

    im trying to programmatically create menu's and sub menus for the main menu given, it doesnt seem to do it. i FINALLY got all the main menus to appear however all the sub menu's of each menu appear only in one main menu!

    why?? what im i doing wrong?

    Code:
     public class Form1 : System.Windows.Forms.Form
        {
            private System.Windows.Forms.MainMenu fileMenu;
            
            MainMenu someMenu = new MainMenu();
    //..
    //..
    //that is public - the MainMenu object instance
    //..
    //..
    
    //MAIN method
    
    int numberOfFilesFound = 4; //example
    
                someMenu = this.AddMainMenu("File");             
                this.Menu = someMenu;
                this.AddSubMenus(this.Menu, numberOfFilesFound, " Recent File");
    
                someMenu = this.AddMainMenu("Edit");       
                this.Menu = someMenu;
                this.AddSubMenus(this.Menu, numberOfFilesFound, " Recent File");
    
                someMenu = this.AddMainMenu("View");       
                this.Menu = someMenu;
                this.AddSubMenus(this.Menu, numberOfFilesFound, " Recent File");
    
            }
    
            private MainMenu AddMainMenu(string mainMenuName)
            {
                //MainMenu mainMenu = new MainMenu();
                someMenu.MenuItems.Add(mainMenuName);
                
                this.Menu = someMenu;
    
                return this.Menu;
            }
    
            private void AddSubMenus(MainMenu menuName, int numberOfSubItems, string menuItemName)
            {
                for(int x = 1; x <= numberOfSubItems; x++)
                {
                    menuName.MenuItems[0].MenuItems.Add(x + " " + menuItemName);
                }            
                //this.Menu = menuName;
            }
    it adds all the submenus to the file menu, the first menu. how can i tell it after its populated the submenus in the main menu, to move on to the next menu and populate to that one, as it should do logically?

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    all i wanna do is return back the next element or get the next MainMenu index! I cant even do that!!!!! AAAAAAAAAAAAAAAAAAAAAAAAAA

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    got it, finally! aaaaaaaaaaa

    had to just get the global MainMenu.MenuItem[index number] and it seemed to work

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    question remains...

    how would i know how many items there are in a Main Menu and on every sub item to create an onClick event???

    the reason im doing this is because i am going to have a "Recently opened files" sub menu system....

    see what i mean?

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    You will have to loop through your menu recursively.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    im sorry i still dont know what you mean but i think i sorted it by making a new eventhandler when a submenu was being created.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width