本文整理汇总了C#中System.Drawing.Graphics.DrawString方法的典型用法代码示例。如果您正苦于以下问题:C# Graphics.DrawString方法的具体用法?C# Graphics.DrawString怎么用?C# Graphics.DrawString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Graphics
的用法示例。
在下文中一共展示了Graphics.DrawString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawStringFloatFormat
public void DrawStringFloatFormat(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create point for upper-left corner of drawing.
float x = 150.0F;
float y = 50.0F;
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
}
示例2: DrawStringRectangleFFormat
public void DrawStringRectangleFFormat(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create rectangle for drawing.
float x = 150.0F;
float y = 150.0F;
float width = 200.0F;
float height = 50.0F;
RectangleF drawRect = new RectangleF(x, y, width, height);
// Draw rectangle to screen.
Pen blackPen = new Pen(Color.Black);
e.Graphics.DrawRectangle(blackPen, x, y, width, height);
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.Alignment = StringAlignment.Center;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect, drawFormat);
}
示例3: DrawStringFloat
public void DrawStringFloat(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create point for upper-left corner of drawing.
float x = 150.0F;
float y = 150.0F;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y);
}
示例4: DrawStringRectangleF
public void DrawStringRectangleF(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create rectangle for drawing.
float x = 150.0F;
float y = 150.0F;
float width = 200.0F;
float height = 50.0F;
RectangleF drawRect = new RectangleF(x, y, width, height);
// Draw rectangle to screen.
Pen blackPen = new Pen(Color.Black);
e.Graphics.DrawRectangle(blackPen, x, y, width, height);
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawRect);
}
示例5: DrawStringPointF
public void DrawStringPointF(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(150.0F, 150.0F);
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
}
示例6: Main
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class TwoPaintHandlers
{
public static void Main()
{
Form form = new Form();
form.Text = "Two Paint Handlers";
form.BackColor = Color.White;
form.Paint += new PaintEventHandler(PaintHandler1);
form.Paint += new PaintEventHandler(PaintHandler2);
Application.Run(form);
}
static void PaintHandler1(object objSender, PaintEventArgs pea)
{
Form form = (Form)objSender;
Graphics graphics = pea.Graphics;
graphics.DrawString("First Paint Event Handler", form.Font,
Brushes.Black, 0, 0);
}
static void PaintHandler2(object objSender, PaintEventArgs pea)
{
Form form = (Form)objSender;
Graphics graphics = pea.Graphics;
graphics.DrawString("Second Paint Event Handler", form.Font,
Brushes.Black, 0, 100);
}
}
示例7: DrawStringPointFFormat
public void DrawStringPointFFormat(PaintEventArgs e)
{
// Create string to draw.
String drawString = "Sample Text";
// Create font and brush.
Font drawFont = new Font("Arial", 16);
SolidBrush drawBrush = new SolidBrush(Color.Black);
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(150.0F, 50.0F);
// Set format of string.
StringFormat drawFormat = new StringFormat();
drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
// Draw string to screen.
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint, drawFormat);
}