This is a migrated thread and some comments may be shown as answers.

Textbox CanGrow not working as expected

13 Answers 1814 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 10 Mar 2009, 10:51 PM
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.

13 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 13 Mar 2009, 08:04 AM
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.
0
briankb
Top achievements
Rank 2
answered on 02 Jun 2009, 05:46 PM
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?
0
Steve
Telerik team
answered on 03 Jun 2009, 01:48 PM
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.
0
briankb
Top achievements
Rank 2
answered on 03 Jun 2009, 02:12 PM
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.


0
Steve
Telerik team
answered on 03 Jun 2009, 02:56 PM
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.
0
briankb
Top achievements
Rank 2
answered on 03 Jun 2009, 03:09 PM
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.
0
Raido Valgeväli
Top achievements
Rank 2
answered on 06 Jun 2009, 08:12 AM
I think CanGrowVertical (be it current default CanGrow) and CanGrowHorisontal two distinct property choices would be a very good feature for users.
0
M_M
Top achievements
Rank 1
answered on 06 Mar 2012, 06:25 AM
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?
0
Richard
Top achievements
Rank 1
answered on 14 May 2013, 07:05 PM
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.
0
KS
Top achievements
Rank 1
answered on 17 May 2013, 04:55 PM
try to add binding to the text box style.font.size and adjust it with custom function based on the displayed text length
0
Naveen
Top achievements
Rank 1
answered on 22 Jul 2013, 10:58 PM
  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. 
0
KS
Top achievements
Rank 1
answered on 26 Jul 2013, 08:00 AM
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;
       }
0
Giuseppe
Top achievements
Rank 1
answered on 08 Apr 2019, 12:21 PM

Could be a valid answer.

But i would change this

float textBoxWidth = tb.Width.Value

with

float textBoxWidth = tb.Width.ChangeType(UnitType.Pixel).Value
Tags
General Discussions
Asked by
Jeff
Top achievements
Rank 1
Answers by
Svetoslav
Telerik team
briankb
Top achievements
Rank 2
Steve
Telerik team
Raido Valgeväli
Top achievements
Rank 2
M_M
Top achievements
Rank 1
Richard
Top achievements
Rank 1
KS
Top achievements
Rank 1
Naveen
Top achievements
Rank 1
Giuseppe
Top achievements
Rank 1
Share this question
or