C#知识点-GDI绘图

一、开发环境

编译器:VS2013

.Net版本:4.5

二、开发过程

1.画一条直线

private void btnDrawLine_Click(object sender, EventArgs e)
{
    //创建一个画图图面
    Graphics g = this.CreateGraphics();
    //创建一只笔
    Pen pen = new Pen(Brushes.Red);
    //直线的两个坐标
    Point pointStart = new Point(10, 10);
    Point pointEnd = new Point(50, 50);
    //开始画
    g.DrawLine(pen, pointStart, pointEnd);
}

2.画一个矩形

private void btnDrawRectangle_Click(object sender, EventArgs e)
{
    //创建一个画图图面
    Graphics g = this.CreateGraphics();
    //创建一只笔
    Pen pen = new Pen(Brushes.DeepSkyBlue);
    //确定矩形的起点、长和高
    g.DrawRectangle(pen, 50, 50, 60, 30);
}

3.画一个字符串

private void btnDrawString_Click(object sender, EventArgs e)
{
    Graphics g = this.CreateGraphics();
    Font font = new Font("华为宋体", 12);
    //Point一样,只是值是浮点类型
    PointF point = new PointF(50, 50);
    g.DrawString("我是Kimisme", font, Brushes.Coral, point);
}

4.画一个扇形

private void btnDrawSector_Click(object sender, EventArgs e)
 {
     Graphics g = this.CreateGraphics();
     g.DrawPie(new Pen(Brushes.Green),
         new Rectangle(new Point(100, 70),
             new Size(50, 50)), 60, 90);
 }

你可能感兴趣的:(C#知识点-GDI绘图)