Resize Toolstrip TextBoxElement

10 posts, 1 answers
  1. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 13 May 2010 Link to this post

    I came across this forum post, but it wasn't too helpful setting the maximum and minimum don't seem to work quite right.  (Also the post is a little outdated)
    http://www.telerik.com/community/forums/winforms/toolstrip/how-to-resize-textbox-element.aspx


    I am actually trying to make the TextBoxElement smaller.  The default is about twice as wide as I would like (just want to show a page count "X of Y").  Nothing I have tried will reliably change the size of this textbox.  I can get some of it to resize, but then the hosted .NET textbox control is misaligned and so the cursor doesn't look right.  Having the TextBoxElement be this wide is ok if there is no workaround, but it takes up valuable horizontal screen real estate.

    Thanks!
    Adam
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 19 May 2010 Link to this post

    Hello Adam,

    Thank you for writing.

    Actually, you can set the size of RadTextBoxElement through its Min and Max size properties, but you have to do the same for the RadTextBoxItem as well. Please, consider the following code:
     
    int h = this.radTextBoxElement1.Size.Height;
    int w = 50;
    this.radTextBoxElement1.MinSize = new Size(w, h);
    this.radTextBoxElement1.MaxSize = new Size(w, h);
    this.radTextBoxElement1.TextBoxItem.MinSize = new Size(w-5, h);
    this.radTextBoxElement1.TextBoxItem.MaxSize = new Size(w-5, h);

    Hope this helps. Let me know if you have any other questions.

    Greetings,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 19 May 2010 Link to this post

    Your code seemed to work, I was trying to be able to modify the size in the designer, so putting the code in after the InitializeComponents() in the form constructor worked perfectly.

    I'm also having a little trouble with the overflow button.  When the size of the toolstrip gets too small to show all of the items, they correctly disappear from the toolstrip and there is an additional icon shown to indicate that items have been hidden.  However when clicking the overflow button, only an empty menu appears (a menu with 1 item in it with no Image and no Text).  Am I responsible for handling the dropDownOpening event and populating this menu?

    I've got the toolstrip as the only item in a user control, maybe being in a user control has something to do with it?
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 25 May 2010 Link to this post

    Hi Adam,

    Thank you for getting back to me. Actually, we have a known issue with the layout of the hidden elements in the overflow drop-down. We will address it in one of the next releases. For the time being, you can use the workaround which is demonstrated in the sample project attached.

    I hope this helps. If you have additional questions, feel free to contact me.

    Greetings,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 01 Jun 2010 Link to this post

    Is there any other way to wire up the click events on the menu items?  Our toolstrip has several buttons and drop-downs each with separate event handlers.

    For now we are going to just hide all of the overflow button controls and require resizing of the form if any controls are missing.
  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 04 Jun 2010 Link to this post

    Hi Adam,

    Thank you for your question.

    I am not sure whether I understand you correctly, but you can simply subscribe the menu elements to the same events which are used for the tool strip items. This will make sure that clicking on a menu item will bring the functionality of the corresponding tool strip button element.

    Let me know if you need any additional assistance.

    Regards,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  8. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 04 Jun 2010 Link to this post

    Right, but if I am understanding the sample code correctly, basically we are trying to programmatically rebuild the structure of the hidden toolstrip items by creating new RadMenuItems.  Some of our toolstrip buttons are drop down buttons whose children each have their own click event handler.

    The code you provided would require a specific if statement for each menuItem to recreate it in the overflow menu.  I am talking about 50-100 different items, so I was wondering if there was an easier way to wire up the events than to have to check the text of the element and then wire it to a specific event.  This makes for pretty ugly code, especially if we want to change the text of an item in the future, then it will not work when it is in the overflow menu.

    if (newButtonElement.Text == "radButtonElement4") 
        newButtonElement.Click += new EventHandler(newButton_Click); 
    else 
        newButtonElement.Click += new EventHandler(newButton2_Click); 

  9. Answer
    Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 10 Jun 2010 Link to this post

    Hi Adam,

    Thank you for contacting us again.

    There is no need to bind the current toolstrip items to the manually added overflow menu items through their Text property. You are right that this is not a very elegant implementation. Therefore, I have suggested that you simply subscribe to the same event for the new menu items. This way you will not need to maintain changes in RadToolStrip in two places. The modified version of my project includes RadDropDownButtonElement and demonstrates the described approach. You can find this project as an attachment to this message.

    Best wishes,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  10. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 10 Jun 2010 Link to this post

    Thanks Martin for putting me on the right track!!

    I came up with a much more elegant solution to the event wiring problem.  I thought I would share my code here for others to use.

    First off, I preferred the overflow dropDown to appear as a menu than to have all of the overflowed items in a single stack panel, so I create a RadMenuItem for each overflowed element and add it directly to the overflow menu:

                               RadMenuItem newnewButtonElement = new RadMenuItem(); 
                                newButtonElement.TextImageRelation = TextImageRelation.ImageBeforeText; 
                                newButtonElement.Text = ((RadButtonElement)oldItem.ContentElement.Children[i]).Text; 
                                newButtonElement.Image = ((RadButtonElement)oldItem.ContentElement.Children[i]).Image; 
                                newButtonElement.Tag = ((RadButtonElement)oldItem.ContentElement.Children[i]); 
     
                                newButtonElement.Click += new EventHandler(newButtonElement_Click); 
     
                                menu.Items.Add(newButtonElement); 

    The .Tag property and the .Click event handler were the two pieces that streamlined things the best, instead of trying to locate the actual click eventHandler on the original item, I just set the Tag of the item to the original item and call PerformClick() when I need to replicate the click.

            private void newButtonElement_Click(object sender, EventArgs e) 
            { 
                ((sender as RadItem).Tag as RadItem).PerformClick(); 
            } 


  11. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 16 Jun 2010 Link to this post

    Hello Adam,

    Thank you for sharing your solution with community. I have updated your Telerik points for the effort. Do not hesitate to contact us again if you need additional assistance.

    All the best,
    Martin Vasilev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top
UI for WinForms is Visual Studio 2017 Ready