TableLayoutPanel and Autosizing

9 posts, 1 answers
  1. Guillaume Crétot Richert
    Guillaume Crétot Richert avatar
    33 posts
    Member since:
    Oct 2008

    Posted 28 Oct 2008 Link to this post

    Hi,

    I'm trying to add a few Rad controls to a TableLayoutPanel. For the sake of the example, let's say I have a TLP with 1 column and 2 rows. The top row contains a RadListBox, and the bottom row contains a RadButton. The top row's size is set as Percentage (50%) and the bottom row as AutoSize.

    The desired result would be that most of the control's space be filled with the RadListBox, while the RadButton be set at an appropriate size.

    The actual result is that the RadListBox takes up all the room, and the RadButton appears as a tiny sliver at the bottom, barely a line. It would seem as if in run-time, the TableLayoutPanel decides to AutoSize the bottom row to a few pixels; whereas in the form designer, the button appears perfect.

    What am I doing wrong? How can I get the TableLayoutPanel's AutoSizing rows to play nice with RadControls?

    Thank you.
  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 30 Oct 2008 Link to this post

    Hi Guillaume Crétot Richert,

    Thank you for contacting us.

    Please review the attched sample project. Am I missing something while trying to reproduce the issue?

    I am looking forward to help you on your problem.
     

    All the best,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Guillaume Crétot Richert
    Guillaume Crétot Richert avatar
    33 posts
    Member since:
    Oct 2008

    Posted 10 Nov 2008 Link to this post

    Apologies for the late response.

    In the project you provided, the button's dock is set to "None". It should be set to "Fill". Alternatively, you could also set all the button's anchors instead of only top and left like it currently is.

    Once you set the Dock or the Anchors, the button will disappear in run-time (but not in design-time).

    Thank you,
    Guillaume
  4. Nick
    Admin
    Nick avatar
    767 posts

    Posted 11 Nov 2008 Link to this post

    Hello Guillaume Crétot Richert,

    Thank you for contacting us back.

    I see, the reason for that is that autosize uses the size of the inner controls which in the case of RadButton is set to 0. The workaround is to set the row to absolute and use for the size of the row the height of the button. Sorry for the introduced inconvenience.

    Do not hesitate to write me back if you have further questions.

    Kind regards,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  5. Guillaume Crétot Richert
    Guillaume Crétot Richert avatar
    33 posts
    Member since:
    Oct 2008

    Posted 11 Nov 2008 Link to this post

    Hi Nick,

    That's hardly a workaround. My desired behavior is for the button to be autosized. In the case of a RadButton, the heigth can be determined fairly constantly in advance, but for other controls the size can vary immensely depending on where they should appear. I create user controls that contain Telerik controls and can appear in many different sized frames or forms. It would be archaic to have each form dictate which size each of its buttons should have.

    Are there any plans to have RadControls implement AutoSize correctly? It's a pretty big feature to cut out of wincontrols, and I'm surprised this is the first time I read about it being missing from Telerik's product.

    Thanks!
  6. Answer
    Nick
    Admin
    Nick avatar
    767 posts

    Posted 12 Nov 2008 Link to this post

    Hi Guillaume Crétot Richert,

    Thank you for contacting me back.

    The subclassed RadButton will work correctly in your application.

    public class RadButtonElement2 : RadButtonElement 
      protected override System.Drawing.SizeF MeasureOverride(System.Drawing.SizeF availableSize) 
      { 
        if (availableSize.Width == 0) 
        { 
        return new SizeF(23, availableSize.Height); 
        } 
        return base.MeasureOverride(availableSize); 
       } 
     
       protected override Type ThemeEffectiveType 
       {  
         get 
         { 
            return typeof(RadButtonElement);  
         } 
       } 
      } 
     
    public class RadButton2 : RadButton 
       { 
          RadButtonElement2 element = new RadButtonElement2(); 
          public RadButton2() 
          { 
            this.UseNewLayoutSystem = true
            this.AutoSize = false
          } 
     
       public override RadButtonElement ButtonElement 
       { 
         get  
         {  
           return this.element; 
         } 
       } 
     
     
       public override string ThemeClassName 
       { 
        get 
        { 
          return typeof(RadButton).FullName; 
        } 
        set 
        { 
          base.ThemeClassName = value; 
        } 
      } 


    Do not hesitate to write me back if you have further questions.

    Greetings,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Guillaume Crétot Richert
    Guillaume Crétot Richert avatar
    33 posts
    Member since:
    Oct 2008

    Posted 12 Nov 2008 Link to this post

    Hot damn!

    As soon as I get around to it, I'll rewrite your code in VB and try it out. I'll let you know how it turns out ASAP.

    Thanks for your time!
  8. Nick
    Admin
    Nick avatar
    767 posts

    Posted 13 Nov 2008 Link to this post

    Hi Guillaume Crétot Richert,

    You may use this online tool to convert the code.

    Regards,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Guillaume Crétot Richert
    Guillaume Crétot Richert avatar
    33 posts
    Member since:
    Oct 2008

    Posted 17 Nov 2008 Link to this post

    Works like a charm!

    Thanks Nick!
Back to Top