BLOG.CSHARPHELPER.COM: Use a StringFormat object and a Rectangle to align painted text in C#
Use a StringFormat object and a Rectangle to align painted text in C#
This example's Paint event handler draws nine strings inside a rectangle aligned vertically and horizontally in the nine possible
combinations: top/left, top/center, bottom/right, etc.
The StringFormat object's LineAlignment property determines how the text is aligned vertically. It can take the values Near (top), Center (middle), or Far (bottom).
The Alignment property determines how the text is aligned horizontally. It can take the same values Near (left), Center (middle), or Far (right).
The following code shows how the program draws its text aligned in the upper left corner. To draw the rest of the text, the program uses different Alignment and LineAlignment values.
Comments