c# 如何在画布上绘制一个点,一条线,或者是一个多边形呢- <p>private void button1_Click(object sender, EventArgs e)
-
- {
- using (Graphics x = Graphics.FromImage(flag))
-
- {
-
- x.Clear(Color.White);
-
- //Brush brush = new SolidBrush(Color.Red);
-
- Pen pen = new Pen(Color.Black, 1);
-
- #region//这里有26个控制点的坐标是通过Calu方法计算得来的,所以看着有些怪异
-
- Point ptA = new Point(Calu(0.00), picbox1.Width - Calu(0.00) - 10);//A
-
- Point ptB = new Point(Calu(50.00), picbox1.Width - Calu(86.60) - 10);//B
-
- Point ptC = new Point(Calu(100.00), picbox1.Width - Calu(0.00) - 10);//C
-
- Point ptD = new Point(Calu(15.00), picbox1.Width - Calu(0.00) - 10);//D
-
- ....删减一部分...
-
- #endregion
-
- Point[] pt1 = new Point[5];
-
- pt1[0] = ptL; pt1[1] = ptQ; pt1[2] = ptR; pt1[3] = ptM; pt1[4] = ptB;
-
- x.DrawPolygon(pen, pt1);//绘制多边形区块1;(绘制一个多边形,他的顶点时pt1里边的五个点)
- Rectangle rect = new Rectangle(drawPoint.X, drawPoint.Y, 3, 3);//定义矩形,参数为起点横纵坐标以及其长和宽</p><p> //单色填充
- SolidBrush b1 = new SolidBrush(Color.Blue;//定义单色画刷
- x.FillRectangle(b1, rect);//填充这个矩形(绘制一个点,并用一个3*3的矩形来表示它的位置)
- x.DrawLine(pen,ptA ,ptB);(绘制一条线)
-
- }
-
- }
- </p>
复制代码 基本的在c#中进行点线面的绘制,当然还有很多其他更好的方法,特殊的需要,大家共同探讨
|