Home > Enterprise >  How do you detect if a specific string will either fit or take up a second line in a textbox in Crys
How do you detect if a specific string will either fit or take up a second line in a textbox in Crys

Time:03-02

So basically I have a textbox with a specific width and I need to know if the string I will put into it will either fit nicely in one line or take a second line. For example: I have

string v = "WERTYUIOSDFGHJKWERTYUISDFGHJKXCVBNSDFGHJ"

and a textbox that's 3000 in width.

At first I tried: if v.length = x then... where x is the length of the string that can fit into the textbox. But I soon found out that strings with mostly 'I' can fit more inside compared to a string of mostly 'M'. And that is where the problem lies. Is there a function that detects if the string is going to take/need a second line?

CodePudding user response:

Another option is to create or use a 3rd-party Crystal Reports UFL (User Function Library). A list of 3rd-party UFLs is maintained by Ken Hamady here.

At least one of these UFLs provides functions that allow Crystal formulas to either:

a. specify as input the text, font name, font size, bold and italics status and get the required width (in pixels or twips), or

b. specify the available width for the text and get the maximum font size to fit, or the number of lines required for a given font size.

The advantage of using a UFL approach is that Crystal supports dynamic property expressions. That means that the result of the function call can dynamically control a property such as font size, height, position, etc.

  • Related