Textbox CanGrow not working as expected

13 posts, 0 answers
  1. Jeff
    Jeff avatar
    2 posts
    Member since:
    Jan 2009

    Posted 10 Mar 2009 Link to this post

    Hello.  We've recently purchased Telerik Reporting and so far for our initial needs, it's been great.  But now for a new project, we are trying to basically create a large contract/invoice template.  The reason is we have 13 different contract types that can be created, but they all have the same text in sections while different text in others.  For the changed text, we are pulling it from a SQL DB and putting it into textboxes in this new report.

    The problem is how the CanGrow property of the Textbox behaves.  In our original need, we set the width for a basic name/address textbox to be the max it would ever be, but the height to be small.  When the data was pulled in, the textbox would automatically grow vertically to accomodate all the data.  Our needs are different this time and instead of the textbox auto-growing vertically, we need it to auto-grow horizontally (or shrink as well).  So if we set a textbox to a size that's too big for "tiny text", it would auto-shrink horizontally to fit, or auto-grow for text like "This is a very long sentence that wouldn't normally fit into the textbox width".

    My question is, if this is possible, how do we do this?  We've tried setting both CanGrow and CanShrink to True, also tried setting MultiLine and TextWrap to False, but nothing seems to work.  Is there any way?  Thank you.
  2. Svetoslav
    Admin
    Svetoslav avatar
    649 posts

    Posted 13 Mar 2009 Link to this post

    Hello Steve,

    The TextBox report item can change its size in the vertical direction only and there is no way of changing this behavior. The reason for this is that if the item can grow in both directions the task of calculating its size becomes ambiguous. So we decided to fix the width of the TextBox and let it grow by height only.

    Regards,
    Svetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. briankb
    briankb avatar
    88 posts
    Member since:
    Feb 2004

    Posted 02 Jun 2009 Link to this post

    Is it possible to have the textbox make the font size smaller so that the height and width set for the textbox is not changed?

    For instance a textbox with a height of 1" and width of 4" could use a font with 18pt if the text is only 10 characters. However if the text length is doubled say 20 characters the font would need to be around 12pt or so. These are just example numbers to illustrate.

    How can I get this functionality with Telerik Reporting?
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 03 Jun 2009 Link to this post

    Hi briankb,

    Auto-sizing the contents inside a textbox item is not and would not be possible because it is simply wrong design. What would happen with the report layout if an auto-size is applied only for a single item?

    Kind regards,
    Steve
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. briankb
    briankb avatar
    88 posts
    Member since:
    Feb 2004

    Posted 03 Jun 2009 Link to this post

    I was previously using a PDF generator from Cete.com to create dynamic PDF's I use on a specific ecommerce site to create various reports and single page letters. CETE's Dynamic PDF generator does exactly what I'm describing and I recently started trying to move from their product to Telerik Reporting. So far I've been lucky and very happy with the transition.

    If you have a textbox that is set to a specific height and width and for whatever reason the string that is being pushed into the textbox from a database is longer than expected you have three options: a) display as much of the text as possible then stop b) allow the text to go outside the h&w of the textbox (using cangrow) or c) change the font size so the text will fit completely inside the textbox.


  7. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 03 Jun 2009 Link to this post

    Hi Brian,

    I was just expressing our opinion on the matter and that we believe that such implementation is wrong according to us.
    Options a) and b) are both handled currently with the help of the MultiLine, TextWrap and CanGrow properties with the exception that the textbox would never change its width as explained in previous reply from my colleague.
    Option c) is the one in question. Again we would ask, what would happen with the report layout if an auto-size is applied only for a single item i.e. you have whole report with various items in it and let's say that all have option c) enabled. What is the chance of having this applied to all items however? You would have some items with 18pt, others with 12 pt. etc.

    Regards,
    Steve
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. briankb
    briankb avatar
    88 posts
    Member since:
    Feb 2004

    Posted 03 Jun 2009 Link to this post

    I'm only talking about having it applied to a single item or items you specify.

    If a Telerik Report Textbox had one additional property called "Maintain Height and Width" or "Shrink Text to Fit Height and Width" then you could specify it for one specific textbox without effecting the entire report. I believe the reason we are having issues discussing this is because you are thinking of Telerik Report as an actual multipage report when in this case it is being used to generate a Single Page PDF or JPG.

    Perhaps my use of Telerik Report is not typical and is not within the constraints established in your examples. However I don't really have a need to use Telerik Report as a typical report generator so I'm using it to solve another problem for me. Generating single page promotional materials with a username which is placed into a textbox which is set upon a professionally designed background image with specific placement of the textbox required. The textbox can not grow or shrink. So the text inside will have to do that if needed to maintain the graphic design of the page. People don't always use your products as you expect and that is a good thing, isn't it?

    What I'm going to do today since we are in hovering mode here. Is to check the length of the string programmatically and change the Font Size accordingly before the page is rendered. Like I said adding a property to the textbox and handling this would make things very nice.
  9. Raido Valgeväli
    Raido Valgeväli avatar
    26 posts
    Member since:
    May 2008

    Posted 06 Jun 2009 Link to this post

    I think CanGrowVertical (be it current default CanGrow) and CanGrowHorisontal two distinct property choices would be a very good feature for users.
  10. M_M
    M_M avatar
    3 posts
    Member since:
    Jan 2010

    Posted 06 Mar 2012 Link to this post

    Hi.
    i'm having the same problem, I want to Shrink my text into TextBoxes, even if their text need to be resized and be smaller than another texts. (This behavior is quite normal, in Microsoft Excel you have a "Shrink To Fit" ability which can be applied to any of the cells)

    briankb
    can i please ask you how you achieved this goal? for measuring the size of a text programmatically, you need the "Graphics" object of the page, when and how can you access to this object?
  11. Richard
    Richard avatar
    4 posts
    Member since:
    Apr 2013

    Posted 14 May 2013 Link to this post

    I would like to add that I too would like to see this feature.

    We have a print shop in which we print a lot of pre-printed forms. I can't let the controls grow vertically (or at all for that matter). If there is a "description" field that the users don't care what size it is as long as they can see the whole of the text (within reason of course), then that would be nice.

    I actually ran across this post because of this very situation.
  12. KS
    KS avatar
    165 posts
    Member since:
    Oct 2012

    Posted 17 May 2013 Link to this post

    try to add binding to the text box style.font.size and adjust it with custom function based on the displayed text length
  13. Naveen
    Naveen avatar
    3 posts
    Member since:
    Aug 2012

    Posted 22 Jul 2013 Link to this post

      Currently, i am using a picture box and on the top of that i have a text box. When the textbox has more text than expected, i wish the text auto-adjust its size and display accordingly.
      Is "Wrong design" is an excuse for not having that feature. Atleast i feel that way. 
  14. KS
    KS avatar
    165 posts
    Member since:
    Oct 2012

    Posted 26 Jul 2013 Link to this post

    Hi,

    Try binding the Style.Font.Size property to this kind of user function(calculations may need to be adjusted, but generally this is the idea of resizing the font):
    public static Unit TextBoxAutoFontSize(string value, object reportitem)
           {
     
               Telerik.Reporting.Processing.TextBox tb = reportitem as Telerik.Reporting.Processing.TextBox;
     
               //the textBox item width in pixels
               float textBoxWidth = tb.Width.Value;
     
               //the fontsize should be in points
               string fontname = tb.Style.Font.Name;
               float fontsize = tb.Style.Font.Size.Value;
     
               Size size = TextRenderer.MeasureText(value, new System.Drawing.Font(fontname, fontsize));
     
               while ((float)size.Width + 10 > textBoxWidth && fontsize > 0.1)
               {
                   fontsize--;
                   size = TextRenderer.MeasureText(value, new System.Drawing.Font(fontname, fontsize));
               }
               Unit result = new Unit(fontsize, UnitType.Point);
               return result;
           }
Back to Top
DevCraft banner