String Break - Adds line breaks to strings by analyzing content

More
3 years 6 months ago #331 by John Fauss
John Fauss created the code: String Break - Adds line breaks to strings by analyzing content
When attempting to display the contents of a long string into an area having limited width, but with room for multiple lines, PowerBuilder & Windows will simulate a line break only where it finds white space in the string. Sometimes this behavior is adequate, but when the string lacks spaces the data is usually cropped.

Wouldn't it be nice to also simulate a line break after a hyphen or before a left parenthesis? Well, now you can be in control of the parsing conditions that determine where a line break occurs.

The attached sample PB application utilizes a non-visual object that analyzes the contents of a string while taking the width and height of a Static Text control, Text or Computed Field DataWindow Objects and their font properties (typeface, point size, weight, etc.) into account. You can specify the maximum number of display lines and which characters a line break can be inserted ahead of and/or after, if needed. In the event there is insufficient room to display all of the data, you can optionally request the last line end with an ellipsis (...).

The NVO and sample application are generously commented. A log of the parsing analysis can be viewed. The sample application shows how a recently-posted problem in the Q&A section of the Appeon Community can be solved.

As an added bonus, the sample application also illustrates how the DrawTextEx Windows API function can be used to replace a portion of a file's path with an ellipsis to allow it to be displayed without truncating the filename and extension.

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #430 by John Fauss
John Fauss replied the code: String Break - Adds line breaks to strings by analyzing content
Thank you, Miguel! I appreciate the feedback. This was a fun project and I learned a lot from it.

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #429 by Miguel Leeuwe
Miguel Leeuwe replied the code: String Break - Adds line breaks to strings by analyzing content
John this is so awesome!

Please Log in or Create an account to join the conversation.

Moderators: Appeon Administrator