I have a TextBox
where I need to show some text. The length of the text is dynamic, so it needs to be wrapped to fit into multiple lines.
The maximum length of a line is 50 characters. If the text is more than that, I need to add a line break \n
.
For example, if the text is 165 chars:
- Add a
\n
at 51st position - Add a
\n
at 102nd position - Add a
\n
at 153rd position
So finally the total length of text will be 168 chars.
I know how to do this using a loop. But my question is, can this be done without much code? Does the String class have a method to provide that function?
This is a Windows Forms app, but all controls including TextBox
are created programmatically.