Enable / Disable Cloned Context Menu Items
-
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**
-
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**
mnShow
andmnHide
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-----
-
mnShow
andmnHide
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-----
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**
-
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**
Wherever you cloned your menus, those
mnShowClone
andmnHideClone
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 likemnShow
andmnHide
) 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-----
-
Wherever you cloned your menus, those
mnShowClone
andmnHideClone
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 likemnShow
andmnHide
) 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-----
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**
-
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**
Opps Sorry I posted as Anonymous **DAN**
-
Opps Sorry I posted as Anonymous **DAN**
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**