logo
Учебник_ПОА

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

Пример можно скомпилировать непосредственно в командной строке либо вставить код в консольное приложение с помощью IDE Visual Studio. В последнем случае необходимо добавить ссылку на файл System.Windows.Forms.dll20.

Надежное программирование

Исключение может возникнуть при следующих условиях.

Drawing Text and Graphics

This topic is designed to help you find code that demonstrates how to perform common graphics programming tasks by using Visual C# Express Edition.

How to: Draw Text on a Form

This example demonstrates how to draw text on a form.

Example

private void DrawString()

{

System.Drawing.Graphics formGraphics = this.CreateGraphics();

string drawString = "Sample Text";

System.Drawing.Font drawFont = new System.Drawing.Font(

"Arial", 16);

System.Drawing.SolidBrush drawBrush = new

System.Drawing.SolidBrush(System.Drawing.Color.Black);

float x = 150.0f;

float y = 50.0f;

formGraphics.DrawString(drawString, drawFont, drawBrush, x, y);

drawFont.Dispose();

drawBrush.Dispose();

formGraphics.Dispose();

}