如何:在窗体上绘制文本
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();
}
如何:更改 Windows 窗体控件上文本的颜色
label1.ForeColor=System.Drawing.Color.Pink;
如何:在 Windows 窗体上绘制图形
System.Drawing.Graphics graphics = this.CreateGraphics();
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(
100, 100, 200, 200);
graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);
如何:在窗体上绘制曲线
System.Drawing.Graphics formGraphics = this.CreateGraphics();
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
// Draw head with an ellipse.
formGraphics.DrawEllipse(myPen, 0, 0, 200, 200);
// Draw winking eye with an arc.
formGraphics.DrawArc(myPen, 40, 40, 40, 40, 180, -180);
// Draw open eye with an ellipse.
formGraphics.DrawEllipse(myPen, 120, 40, 40, 40);
// Draw nose with a Bezier spline.
formGraphics.DrawBezier(myPen, 100, 60, 120, 100, 90, 120, 80, 100);
// Draw mouth with a canonical spline.
Point[] apt = new Point[4];
apt[0] = new Point(60, 140);
apt[1] = new Point(140, 140);
apt[2] = new Point(100, 180);
apt[3] = new Point(60, 140);
formGraphics.DrawCurve(myPen, apt, 0, 3, 0.9f);
myPen.Dispose();
formGraphics.Dispose();
如何:绘制空心形状
private void DrawEllipse()
{
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.DrawEllipse(myPen, new Rectangle(0,0,200,300));
myPen.Dispose();
formGraphics.Dispose();
}
private void DrawRectangle()
{
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.DrawRectangle(myPen, new Rectangle(0,0,200,300));
myPen.Dispose();
formGraphics.Dispose();
}
如何:在窗体上绘制直线
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.DrawLine(myPen, 0, 0, 200, 200);
myPen.Dispose();
formGraphics.Dispose();
如何:在窗体上绘制实心矩形
System.Drawing.SolidBrush brush1 =
new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(brush1, new System.Drawing.Rectangle(0,0,200,300));
brush1.Dispose();
formGraphics.Dispose();
如何:在窗体上绘制实心椭圆
System.Drawing.SolidBrush brush1 =
new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(brush1, new System.Drawing.Rectangle(0,0,200,300));
brush1.Dispose();
formGraphics.Dispose();
如何:创建实心画笔 (Visual C#)
System.Drawing.SolidBrush myBrush;
myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
myBrush.Dispose();
如何:创建钢笔 (Visual C#)
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
myPen.Dispose();
如何:设置钢笔的颜色 (Visual C#)
myPen.Color = System.Drawing.Color.PeachPuff;