Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. EventHandler not Fire

EventHandler not Fire

Scheduled Pinned Locked Moved C#
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mfcuser
    wrote on last edited by
    #1

    I want to know why this does not work. It is very simple, but when I click on it, it does not show the message box. I want to know why. MainMenu mainMenu1 = new MainMenu(); MenuItem menuItem1 = new MenuItem("&File"); menuItem1.MenuItems.Add("Data"); menuItem1.MenuItems.Add("Computer"); menuItem1.MenuItems.Add("Keyboard"); menuItem1.MenuItems.Add("Telephone"); menuItem1.Click += new EventHandler(OnComputer); void OnComputer(object sender, EventArgs e) { MessageBox.Show("You click on computer", "Computer Click"); }

    C 1 Reply Last reply
    0
    • M mfcuser

      I want to know why this does not work. It is very simple, but when I click on it, it does not show the message box. I want to know why. MainMenu mainMenu1 = new MainMenu(); MenuItem menuItem1 = new MenuItem("&File"); menuItem1.MenuItems.Add("Data"); menuItem1.MenuItems.Add("Computer"); menuItem1.MenuItems.Add("Keyboard"); menuItem1.MenuItems.Add("Telephone"); menuItem1.Click += new EventHandler(OnComputer); void OnComputer(object sender, EventArgs e) { MessageBox.Show("You click on computer", "Computer Click"); }

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      That looks like you've assigned it to the File item, not the Computer item.


      Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos

      M 1 Reply Last reply
      0
      • C Colin Angus Mackay

        That looks like you've assigned it to the File item, not the Computer item.


        Upcoming events: * Glasgow: Geek Dinner (5th March) * Edinburgh: Web Security Conference Day for Windows Developers (12th April) My: Website | Blog | Photos

        M Offline
        M Offline
        mfcuser
        wrote on last edited by
        #3

        The computer item is a subitem of the file menu. So how can I assign it to the computer item. How can I fix that?

        R 1 Reply Last reply
        0
        • M mfcuser

          The computer item is a subitem of the file menu. So how can I assign it to the computer item. How can I fix that?

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          mfcuser wrote:

          how can I assign it to the computer item.

          MainMenu mainMenu1 = new MainMenu();
          MenuItem menuItem1 = new MenuItem("&File");
          menuItem1.MenuItems.Add("Data");
          MenuItem computerMenuItem = new MenuItem("Computer"); menuItem1.MenuItems.Add(computerMenuItem);
          menuItem1.MenuItems.Add("Keyboard");
          menuItem1.MenuItems.Add("Telephone");

          computerMenuItem.Click += new EventHandler(OnComputer);

          void OnComputer(object sender, EventArgs e)
          {
          MessageBox.Show("You click on computer", "Computer Click");
          }

          /ravi

          This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          M 1 Reply Last reply
          0
          • R Ravi Bhavnani

            mfcuser wrote:

            how can I assign it to the computer item.

            MainMenu mainMenu1 = new MainMenu();
            MenuItem menuItem1 = new MenuItem("&File");
            menuItem1.MenuItems.Add("Data");
            MenuItem computerMenuItem = new MenuItem("Computer"); menuItem1.MenuItems.Add(computerMenuItem);
            menuItem1.MenuItems.Add("Keyboard");
            menuItem1.MenuItems.Add("Telephone");

            computerMenuItem.Click += new EventHandler(OnComputer);

            void OnComputer(object sender, EventArgs e)
            {
            MessageBox.Show("You click on computer", "Computer Click");
            }

            /ravi

            This is your brain on Celcius Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

            M Offline
            M Offline
            mfcuser
            wrote on last edited by
            #5

            It is working fine now. About if I have several menu items. There must be a way to pack them to an array rather than doing it one by one. So the way I had "Data", "Keyboard", "Telephone" was incorrect. The menu items need to have their own variable to identify them rather than single string.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups