Measuring the length of a string in a textbox at run time

Posted by: Administrator on 25 September 2018, 7:06 pm EST

    • Post Options:
    • Link

    Posted 25 September 2018, 7:06 pm EST

    I have a textbox that CANNOT grow. It cannot grow because it is part of a government form.

    That means I need to know at run time, what part of the string will run out of the text box, so I handle the rest of the string that does not fit. The width of the text box is in inches, not in pixels, so that can be challenging.

    So big letters like the capital “M” will take up more while the small “i” takes up less. Also needs to be taken into account the font and size as well. There won’t be italic and bold texts.

  • Posted 25 September 2018, 8:43 pm EST

    Hello,

    Could you please tell which report type are your using( Section/RDL/Page). Also, you can use the “ShrinkToFit” property of “TextBox” to automatically fit the text in the desired size.

    If the above solution is not suitable for you please let me know.

    Thanks,

  • Posted 26 September 2018, 7:13 am EST

    That will not work. The font and size are fixed. ShrinkToFit would make the text very tiny.

    I am using version 10, SectionReport.

  • Posted 26 September 2018, 6:18 pm EST

    Hello,

    To achieve your requirement you need to do the following thing:

    1: Convert the size of “TextBox” to pixels

    2: Check that at what amount of Text fit into the above textbox size.

    3: Get the remaining string

    You can do the above thing in “Format” event of the SectionReport

    However, 2 steps may lead to performance issue if you have a large report or too many textboxes.

    Hope it clarifies.

    Thanks,

  • Posted 6 September 2020, 3:13 am EST

    How do we convert the size of an Active Reports textbox to pixels? I have not been able to find any information on this.

  • Posted 6 September 2020, 9:54 pm EST

    Hello,

    You can refer to the following link to convert the TextBox size in to Pixel:

    https://stackoverflow.com/questions/20727525/calculate-inches-and-centimeters-from-pixels-in-c-sharp

    Also, refer to the following link to use scripting in the section report:

    https://www.grapecity.com/activereports/docs/v14/online/scripts.html

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels