//在窗体重新绘制的时候,重新加载划线
private void Form1_Paint(object sender, PaintEventArgs e)
{
//创建GDI图像
Graphics graphics = this.CreateGraphics();
//创建画笔对象
Pen pen = new Pen(Brushes.Red);
//创建两个点
Point p1 = new Point(30, 50);
Point p2 = new Point(300, 500);
//调用GDI方法开始画直线
graphics.DrawLine(pen, p1, p2);
}
private void button1_Click(object sender, EventArgs e)
{
//创建GDI图像
Graphics graphics = this.CreateGraphics();
//创建画笔对象
Pen pen = new Pen(Brushes.Red);
//创建两个点
Point p1 = new Point(30, 50);
Point p2 = new Point(300, 500);
//调用GDI方法开始画直线
graphics.DrawLine(pen, p1, p2);
}
来源:CSDN
作者:马一林
链接:https://blog.csdn.net/qq_29760029/article/details/103983040