logo
CSharp_Graphics

Компиляция кода

Для выполнения приведенных примеров требуются следующие компоненты.

How to: Draw Wrapped Text in a Rectangle

You can draw wrapped text in a rectangle by using the DrawString overloaded method of the Graphics class that takes a Rectangle or RectangleF parameter. You will also use a Brush and a Font.

You can also draw wrapped text in a rectangle by using the DrawText overloaded method of the TextRenderer that takes a Rectangle and a TextFormatFlags parameter. You will also use a Color and a Font.

The following illustration shows the output of text drawn in the rectangle when you use the DrawString method.

To draw wrapped text in a rectangle with GDI+

string text1 = "Draw text in a rectangle by passing a RectF to the DrawString method.";

using (Font font1 = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point))

{

RectangleF rectF1 = new RectangleF(30, 10, 100, 122);

e.Graphics.DrawString(text1, font1, Brushes.Blue, rectF1);

e.Graphics.DrawRectangle(Pens.Black, Rectangle.Round(rectF1));

}