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. Enable / Disable Cloned Context Menu Items

Enable / Disable Cloned Context Menu Items

Scheduled Pinned Locked Moved C#
helpquestion
7 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.
  • D Offline
    D Offline
    Daniel Negron
    wrote on last edited by
    #1

    I have cloned the mainMenu to the context Menu. If I set the .Enabled or .Disabled in the form load event. These feature works properly. But If I minimize the form to use the contextMenu, the mnHide menuItem is not Hidden. If I click on Hide when the form is hidded, this causes the form to be squeezed to just the min, max and close buttons, when I do finaly hit the Show button. Right now my issue is getting the mnHide button to hide, but this isn't working? Is there another way to hide the cloned context menu items ? // //contextMenu1 // this.contextMenu1.MenuItems.Add(mnShow.CloneMenu()); this.contextMenu1.MenuItems.Add(mnHide.CloneMenu()); private void contextMenu1_Popup(object sender, System.EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.mnShow.Enabled = true; this.mnHide.Enabled = false; } else { this.mnShow.Enabled = false; this.mnHide.Enabled = true; } } Thanx in advance for your help. **DAN**

    H 1 Reply Last reply
    0
    • D Daniel Negron

      I have cloned the mainMenu to the context Menu. If I set the .Enabled or .Disabled in the form load event. These feature works properly. But If I minimize the form to use the contextMenu, the mnHide menuItem is not Hidden. If I click on Hide when the form is hidded, this causes the form to be squeezed to just the min, max and close buttons, when I do finaly hit the Show button. Right now my issue is getting the mnHide button to hide, but this isn't working? Is there another way to hide the cloned context menu items ? // //contextMenu1 // this.contextMenu1.MenuItems.Add(mnShow.CloneMenu()); this.contextMenu1.MenuItems.Add(mnHide.CloneMenu()); private void contextMenu1_Popup(object sender, System.EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.mnShow.Enabled = true; this.mnHide.Enabled = false; } else { this.mnShow.Enabled = false; this.mnHide.Enabled = true; } } Thanx in advance for your help. **DAN**

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      mnShow and mnHide are not the correct objects to enable / disable. Remember, you cloned them so they are not the same object reference. Instead, try something like this:

      Menu mnShowClone = mnShow.CloneMenu();
      Menu mnHideClone = mnHide.CloneMenu();
      this.contextMenu1.MenuItems.Add(mnShowClone);
      this.contextMenu1.MenuItems.Add(mnHideClone);
       
      // ...
       
      private void contextMenu1_Popup(object sender, EventArgs e)
      {
      mnShowClone.Enabled = this.WindowState == FormWindowState.Minimized;
      mnHideClone.Enabled = !mnShowClone.Enabled;
      }

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      D 1 Reply Last reply
      0
      • H Heath Stewart

        mnShow and mnHide are not the correct objects to enable / disable. Remember, you cloned them so they are not the same object reference. Instead, try something like this:

        Menu mnShowClone = mnShow.CloneMenu();
        Menu mnHideClone = mnHide.CloneMenu();
        this.contextMenu1.MenuItems.Add(mnShowClone);
        this.contextMenu1.MenuItems.Add(mnHideClone);
         
        // ...
         
        private void contextMenu1_Popup(object sender, EventArgs e)
        {
        mnShowClone.Enabled = this.WindowState == FormWindowState.Minimized;
        mnHideClone.Enabled = !mnShowClone.Enabled;
        }

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        D Offline
        D Offline
        Daniel Negron
        wrote on last edited by
        #3

        when I try to create a new reference to I get : **The type or namespace name 'mnShowClone' could not be found (are you missing a using directive or an assembly reference?)** Am I just supposed to be referencing the Menu itself or the MenuItem ? **DAN**

        H 1 Reply Last reply
        0
        • D Daniel Negron

          when I try to create a new reference to I get : **The type or namespace name 'mnShowClone' could not be found (are you missing a using directive or an assembly reference?)** Am I just supposed to be referencing the Menu itself or the MenuItem ? **DAN**

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Wherever you cloned your menus, those mnShowClone and mnHideClone menus have to be accessible, i.e. if you declare them inside a method they will not be available inside another method. Instead, add them as class fields (just like mnShow and mnHide) and assign them if they haven't been assigned already (as part of initialization code or something).

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          A 1 Reply Last reply
          0
          • H Heath Stewart

            Wherever you cloned your menus, those mnShowClone and mnHideClone menus have to be accessible, i.e. if you declare them inside a method they will not be available inside another method. Instead, add them as class fields (just like mnShow and mnHide) and assign them if they haven't been assigned already (as part of initialization code or something).

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Unbelievably, as easy as this may be, for myself it is still not working. private void InitializeComponent() { ... excess code removed // // contextMenu1 // MenuItem mnShowClone = this.mnShow.CloneMenu(); MenuItem mnHideClone = this.mnHide.CloneMenu(); // MenuItem mnShowClone = this.mnShow.CloneMenu(); // MenuItem mnHideClone = this.mnHide.CloneMenu(); this.contextMenu1.MenuItems.Add(mnShowClone); this.contextMenu1.MenuItems.Add(mnHideClone); this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup); } public void contextMenu1_Popup(object sender, System.EventArgs e) { // mnShow.Visible = true; // mnHide.Visible = false; mnShowClone.Enabled = this.WindowState == FormWindowState.Minimized; mnHideClone.Enabled = !mnShowClone.Enabled; // if (this.WindowState == FormWindowState.Minimized) // { // this.ConmnShow.Enabled = true; // this.mnHide.Enabled = false; // // } // else // { // ; // this.mnShow.Enabled = false; // this.mnHide.Enabled = true; // } } The lower portion of the last bit of code was what was working when I did not include a MainMenu. Thanks for you help **DAN**

            D 1 Reply Last reply
            0
            • A Anonymous

              Unbelievably, as easy as this may be, for myself it is still not working. private void InitializeComponent() { ... excess code removed // // contextMenu1 // MenuItem mnShowClone = this.mnShow.CloneMenu(); MenuItem mnHideClone = this.mnHide.CloneMenu(); // MenuItem mnShowClone = this.mnShow.CloneMenu(); // MenuItem mnHideClone = this.mnHide.CloneMenu(); this.contextMenu1.MenuItems.Add(mnShowClone); this.contextMenu1.MenuItems.Add(mnHideClone); this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup); } public void contextMenu1_Popup(object sender, System.EventArgs e) { // mnShow.Visible = true; // mnHide.Visible = false; mnShowClone.Enabled = this.WindowState == FormWindowState.Minimized; mnHideClone.Enabled = !mnShowClone.Enabled; // if (this.WindowState == FormWindowState.Minimized) // { // this.ConmnShow.Enabled = true; // this.mnHide.Enabled = false; // // } // else // { // ; // this.mnShow.Enabled = false; // this.mnHide.Enabled = true; // } } The lower portion of the last bit of code was what was working when I did not include a MainMenu. Thanks for you help **DAN**

              D Offline
              D Offline
              Daniel Negron
              wrote on last edited by
              #6

              Opps Sorry I posted as Anonymous **DAN**

              D 1 Reply Last reply
              0
              • D Daniel Negron

                Opps Sorry I posted as Anonymous **DAN**

                D Offline
                D Offline
                Daniel Negron
                wrote on last edited by
                #7

                OK, Today I have my Head screwed on. I got it. I just created a seperate method for creating the contextMenu. Thank you for your help Heath **DAN**

                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