Form1.cs 796 B

123456789101112131415161718192021222324252627282930
  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 WindowsFormsGDIDrawRectangle
  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. //创建画布
  21. Graphics graphics = this.CreateGraphics(); //声明一个Graphics对象
  22. //创建画笔
  23. Pen myPen = new Pen(Color.Black, 8); //实例化Pen类
  24. //调用Graphics对象的DrawRectangle方法
  25. graphics.DrawRectangle(myPen, 10, 10, 150, 100);
  26. }
  27. }
  28. }