C# 画图相关函数,首先要指定在什么地方画,如果没有指定则是默认的位置画。
其实很好理解,要在什么地方画,就要先指定一个容器,就像画画一样,你是要在书上画,还是本子上画,还是在墙上画,书上画,你要指定书的第几页,本子上要指定那一篇,墙上上要指定那一面,一样的道理。
还有一个比较有用的就是抗锯齿显示,默认情况下是没有开启的,需要自己手动开启。gpie.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 这行代码就是开启GDI的抗锯齿功能。
C#的GDI提供了一些基本的画图函数,线 圆 扇形 。。。大家可以自行研究一些,项目是我摘取的的一段代码,方便后面自己用的时候查看。毕竟知识爆炸的时代,好记心不如烂笔头。减少重复思考,提高工作效率还是比较重要的。
// An highlighted block
private void button3_Click(object sender, EventArgs e)
{
Graphics g = groupBox2.CreateGraphics();
Pen pen = new Pen(Color.Green, 1);
Point[] point =
{
new Point(20,20),
new Point(300,20)
};
g.DrawLine(pen, point[0], point[1]);
Graphics gpie = groupBox2.CreateGraphics();//this.CreateGraphics();
Pen pp = new Pen(Color.Green, 2);
Rectangle re = new Rectangle(0, 100-25, 250, 250);
gpie.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gpie.DrawPie(pp, re, 0, -180);
Point[] points =
{
new Point(500,100),
new Point(600,200),
new Point(140,20),
new Point(200,200)
};
pp.Width = 5;
pp.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
pp.DashCap = System.Drawing.Drawing2D.DashCap.Triangle;
gpie.DrawLine(pp, points[0], points[1]);
Graphics gpie1 = tabPage2.CreateGraphics();
Pen pp1 = new Pen(Color.Red, 2);
Rectangle re1 = new Rectangle(0+25, 100, 200, 200);
pp1.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
gpie1.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
gpie1.DrawPie(pp1, re1, 0, -180);
}