c#之GDI简单实现代码及其实例
作业:文档形式
3到5页理解
1.理解
2.源代码解释(1到2页)
3.实现效果
项目地址: https://github.com/zhiyishou/polyer
Demo:https://zhiyishou.github.io/Polyer
[图形学]Delaunay三角剖分算法附C++实现
https://blog.csdn.net/qq_31804159/article/details/81709423
算法丨带内外边界的三角剖分算法(Delaunay)
https://blog.csdn.net/npu2017302288/article/details/80460552
三角剖分算法(delaunay)
https://www.cnblogs.com/zhiyishou/p/4430017.html
GDI
https://www.cnblogs.com/stg609/archive/2008/03/16/1108333.html
1.pen类创建画笔对象:
1) 新建一个Windows应用程序,适当加宽窗体宽度。然后切换到代码方式,添加名称空间引用:
using System.Drawing.Drawing2D;
2) 添加Form1_Paint事件代码
3)在Form1_Load中手动添加paint事件:
this.Paint += new PaintEventHandler(Form1_Paint);
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Drawing.Drawing2D; 7 using System.Linq; 8 using System.Text; 9 using System.Threading.Tasks; 10 using System.Windows.Forms; 11 12 namespace drawpicture 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 public void Form1_Paint(object sender, PaintEventArgs e) 21 { 22 Graphics g = e.Graphics; //创建画板,这里的画板是由Form提供的. 23 Pen pen = new Pen(Color.Blue, 10.5f); 24 g.DrawString("蓝色,宽度为10.5", this.Font, 25 new SolidBrush(Color.Black), 5, 5); 26 g.DrawLine(pen, new Point(110, 10), new Point(380, 10)); 27 pen.Width = 2; 28 pen.Color = Color.Red; 29 g.DrawString("红色,宽度为2", this.Font, 30 new SolidBrush(Color.Black), 5, 25); 31 g.DrawLine(pen, new Point(110, 30), new Point(380, 30)); 32 pen.StartCap = LineCap.Flat; 33 pen.EndCap = LineCap.ArrowAnchor; 34 pen.Width = 9; 35 g.DrawString("红色箭头线", this.Font, 36 new SolidBrush(Color.Black), 5, 45); 37 g.DrawLine(pen, new Point(110, 50), new Point(380, 50)); 38 pen.DashStyle = DashStyle.Custom; 39 pen.DashPattern = new float[] { 4, 4 }; 40 pen.Width = 2; 41 pen.EndCap = LineCap.NoAnchor; 42 g.DrawString("自定义虚线", this.Font, 43 new SolidBrush(Color.Black), 5, 65); 44 g.DrawLine(pen, new Point(110, 70), new Point(380, 70)); 45 pen.DashStyle = DashStyle.Dot; 46 g.DrawString("点划线", this.Font, new SolidBrush(Color.Black), 5, 85); 47 g.DrawLine(pen, new Point(110, 90), new Point(380, 90)); 48 } 49 private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) 50 { 51 52 } 53 54 private void Form1_Load(object sender, EventArgs e) 55 { 56 this.Paint += new PaintEventHandler(Form1_Paint); 57 } 58 59 private void button1_Click(object sender, EventArgs e) 60 { 61 62 } 63 } 64 } 65
运行情况:
2.画刷
public void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush myBrush = new SolidBrush(Color.Red);
g.FillEllipse(myBrush, this.ClientRectangle);
}