none
Check/Uncheck on MenuStrip options RRS feed

  • Question

  • Hi,

    I want to include two modes in my application. The user should be able to select one of the modes from the MenuStrip. When any of the modes is selected, a check sign should appear next to it as is seen in many application. Both the modes cannot be selected together and there is default mode when the applicaition is started.

    Here's an exmaple of check sign on MenuStrip

    http://img32.imageshack.us/img32/4471/screenshotkxi.png

    Saturday, October 9, 2010 4:12 AM

Answers

  • Hi optimus_prime,

    Welcome to MSDN Forums!

     

    1.       Set the method ToolStripMenuItem_Click to deal with the two ToolStripMenuItem click event.

    this.aToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);

    this.bToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);

     

    2.       In Form1.cs:

            private ToolStripMenuItem temp;

            private void Form1_Load(object sender, EventArgs e)

            {

                temp = this.toolStripMenuItem1;

            }

           

            private void ToolStripMenuItem_Click(object sender, EventArgs e)

            {

                // uncheck the old one

                temp.CheckState = CheckState.Unchecked;

                temp = (ToolStripMenuItem)sender;

                // check the new one

                temp.CheckState = CheckState.Checked;

            }

     

    This is also like to group ToolStripMenuItems.

    And you also can take a look at the same skill in another winForm sample:

    http://1code.codeplex.com/SourceControl/changeset/view/55574#1330725

    There’s a complete sample code project for you to clear about this logic and skill.

     

    If there’s anything unclear, please feel free to let me know.

     

    Have a nice day!

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

     

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    • Marked as answer by optimus_prime Friday, October 15, 2010 10:05 AM
    Tuesday, October 12, 2010 8:59 AM
    Moderator

All replies

  • Hi optimus_prime,

    Welcome to MSDN Forums!

     

    1.       Set the method ToolStripMenuItem_Click to deal with the two ToolStripMenuItem click event.

    this.aToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);

    this.bToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);

     

    2.       In Form1.cs:

            private ToolStripMenuItem temp;

            private void Form1_Load(object sender, EventArgs e)

            {

                temp = this.toolStripMenuItem1;

            }

           

            private void ToolStripMenuItem_Click(object sender, EventArgs e)

            {

                // uncheck the old one

                temp.CheckState = CheckState.Unchecked;

                temp = (ToolStripMenuItem)sender;

                // check the new one

                temp.CheckState = CheckState.Checked;

            }

     

    This is also like to group ToolStripMenuItems.

    And you also can take a look at the same skill in another winForm sample:

    http://1code.codeplex.com/SourceControl/changeset/view/55574#1330725

    There’s a complete sample code project for you to clear about this logic and skill.

     

    If there’s anything unclear, please feel free to let me know.

     

    Have a nice day!

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

     

    *****************************************************

    [All-In-One Code Framework]

    Sample world! You will get more from this world!

    Welcome to the new world!

    • Marked as answer by optimus_prime Friday, October 15, 2010 10:05 AM
    Tuesday, October 12, 2010 8:59 AM
    Moderator
  • Dear optimus_prime,

     

    Instead of using checkbox on menuitem you need to use Option/Radio button on menu item. So that your application users will understand he can select only one option among two.

    The best example for this is Windows calculator's View Menu. Here we can select either Standard mode or Scientific mode.

     

    Here is the complete code how to achieve option button on menuitem.How to: Display Option Buttons in a MenuStrip

    Looking for your reply.


    Thanks and Regards, Bharath S.
    Tuesday, October 12, 2010 9:13 AM
  • Thanks! Was dealing with the same issue and wasn't able to fix it, until now ;)
    Monday, December 3, 2012 4:48 PM