Form1.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WindowsFormsGDIDrawPolygon
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. Graphics ghs = this.CreateGraphics(); //实例化Graphics类
  21. Pen myPen = new Pen(Color.Black, 3); //实例化Pen类
  22. Point point1 = new Point(80, 20); //实例化Point类
  23. Point point2 = new Point(40, 50); //实例化Point类
  24. Point point3 = new Point(80, 80); //实例化Point类
  25. Point point4 = new Point(160, 80); //实例化Point类
  26. Point point5 = new Point(200, 50); //实例化Point类
  27. Point point6 = new Point(160, 20); //实例化Point类
  28. Point[] myPoints = { point1, point2, point3, point4, point5, point6 }; //创建Point结构数组
  29. //调用Graphics对象的DrawPolygon方法绘制一个多边形
  30. ghs.DrawPolygon(myPen, myPoints);
  31. }
  32. }
  33. }