locked
Determining size of text in a textbox RRS feed

  • Question

  • Hello all -

    I've got a static sized textbox control (CanGrow and CanShrink = False) that is displaying text returned from a stored procedure, and would like to determine if the text in the textbox overruns the boundaries so that I can add a note to indicate this.  Is there any way to determine if the text is too large for a textbox, or alternately, to determine how many lines a text field will take up when displayed in a textbox?

    I'm using SQLRS 2005.  Thanks in advance for any assistance.

    Thursday, June 24, 2010 11:09 PM

Answers

  • Hi,

    One workaround to this problem that I have used is to play around with the font-size of the text.   I first determine what the maximum number of characters are that can display with my normal fontsize.  Then, if the number of characters exceeds this, I reduce the fontsize at run-time to display the larger text string.  If the text string is so large that the new fontsize is not sufficient to display the whole string, I truncate the string.

    The advantage of this approach is that you can still display lengthy strings at the expense of a slightly smaller font.

    Go to Textbox properties -->Font-->Size expression.

    Here's an example where I have done this.  My normal display font is 10pt, but I have found that it's still readable at 6pt.

    = switch(Len(Fields!Entity.Value) > 20, "6pt",
             Len(Fields!Entity.Value) >= 10 AND Len(Fields!Entity.Value) <= 20, "8pt",
             Len(Fields!Entity.Value) < 10, "10pt")

    Perhaps this approach will work for you.

    Good luck!


    DJAnsc
    • Proposed as answer by Jerry Nee Monday, June 28, 2010 2:54 AM
    • Marked as answer by Jerry Nee Friday, July 2, 2010 6:12 AM
    Friday, June 25, 2010 4:38 PM

All replies

  • There is no direct way to do that. You already set CanGrow and CanShrink = False, keep it that way. then analyze how many characters are fit in to your textbox by executing the report. By this way you will get approx number of characters that can fit in to that textbox in a single line. then to add a note use tooltip property of that textbox and use LEN(<your field>) function like

    =iif(LEN(your field) > number you get from above testing ,"your note here",nothing)

    hope this helps.

    Friday, June 25, 2010 3:02 PM
  • Hi,

    One workaround to this problem that I have used is to play around with the font-size of the text.   I first determine what the maximum number of characters are that can display with my normal fontsize.  Then, if the number of characters exceeds this, I reduce the fontsize at run-time to display the larger text string.  If the text string is so large that the new fontsize is not sufficient to display the whole string, I truncate the string.

    The advantage of this approach is that you can still display lengthy strings at the expense of a slightly smaller font.

    Go to Textbox properties -->Font-->Size expression.

    Here's an example where I have done this.  My normal display font is 10pt, but I have found that it's still readable at 6pt.

    = switch(Len(Fields!Entity.Value) > 20, "6pt",
             Len(Fields!Entity.Value) >= 10 AND Len(Fields!Entity.Value) <= 20, "8pt",
             Len(Fields!Entity.Value) < 10, "10pt")

    Perhaps this approach will work for you.

    Good luck!


    DJAnsc
    • Proposed as answer by Jerry Nee Monday, June 28, 2010 2:54 AM
    • Marked as answer by Jerry Nee Friday, July 2, 2010 6:12 AM
    Friday, June 25, 2010 4:38 PM
  • Thanks for the replies, however checking string length doesn't really help since I'm not using a monospace font.

    To clarify a bit, it's a multi-row textbox, and I'm concerned with the amount of vertical lines the text is taking up.

    Monday, June 28, 2010 6:57 PM