绘制文本和图形

如何:在窗体上绘制文本

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值