Results 1 to 4 of 4

Thread: Put check mark on the item ToolStripDropDownItem using the code

  1. #1
    Join Date
    Apr 2010
    Posts
    30

    Put check mark on the item ToolStripDropDownItem using the code

    I thought this would be a simple matter but its not, this control is not like other controls, it seems. What I try is that I have a menubar/toolbar at the top of the program that I have a dropdown button in and under this I have some items. I should have access to a particular part of this control namely the ability to put a check mark at a selected item in this list but this is not possible to get it via code. I only have it to manually set this in the designer. I want it via code to be able to put a check mark to. And I've tried this code to get it and I get hold of most of the control but it does not have the ability to set or clear the check mark that appears to.

    Code:
    foreach (ToolStripDropDownItem fontItem in this.cmFontSizes.DropDownItems)
    {
                    fontItem.Checked = true;
       }
    It was proved easy to do that and I just used the correct reference. The code is
    Code:
    foreach (ToolStripMenuItem fontItem in this.cmFontSizes.DropDownItems)
                {
                    if (fontItem.Text == "48")
                    {
                        fontItem.Checked = true;
                    }
                    else
                    {
                        fontItem.Checked = false;
                    }
    
                }
    But I am thinking if there is any better way to do this. Do you have any suggestions to this?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Put check mark on the item ToolStripDropDownItem using the code

    You made things harder than what should be and I can not quite see the obvious solution with what you have done. But however this can be done with the help of coding but it is also advisable to use a block if you have a requirement where you have to repeat the same thing more than once. Also if you have to do the same thing repeatedly depending on the condition that might occur, it is always better to use coding rather than going by design. If you don't have the proper result as required then it is definitely that you have done something wrong which is why you didn't got the sufficient output.

  3. #3
    Join Date
    Apr 2010
    Posts
    30

    Re: Put check mark on the item ToolStripDropDownItem using the code

    Thanks for your input. The fact that I use for such things if I imagine that the program will use more resources then it must check every thing but how does a more optimal solution to the code above? What I try in a text editor with RichTextBox as a base and the size of the font will be reflected in the drop down list on where I am or have selected in the textbox. And should I add this button with the code and generate it with the right content every time it opens? But I already tried my way of building up the menu and every time there is a need to view it. Font size is saved in a variable (txtsize) as I move or select anything in richtextbox. The default is 10.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Put check mark on the item ToolStripDropDownItem using the code

    Run this code once when the program starts, and I think your solution is so good that it should be working. However keep a note of it that you use static readonly on values that are only to be read, this is a little bit faster than without any reason. Also change the code that generates the click and set a new font in the editor, like this:

    Code:
    void act font size click(object send, EventArgs e)
    {
            ToolStripItem item = (ToolStripItem)transmitter;
            change font size(float.Parse(item.Text));
    }

Similar Threads

  1. Replies: 4
    Last Post: 15-10-2011, 12:11 PM
  2. Replies: 3
    Last Post: 21-03-2011, 04:33 PM
  3. Green check mark on the icon MS office document?
    By Hemendu in forum Windows Software
    Replies: 3
    Last Post: 24-11-2010, 06:19 AM
  4. Replies: 3
    Last Post: 12-11-2010, 03:38 AM
  5. How to check regex for Zip Code
    By Neil'o in forum Windows Software
    Replies: 3
    Last Post: 29-07-2009, 12:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,710,847,119.68732 seconds with 17 queries