using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 画直线
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Red,5);//新建画笔
Point startPoint = new Point(50, 80);//起始点
Point endPoint = new Point(250, 80);//结尾点
g.DrawLine(p, startPoint, endPoint);//画直线
g.Dispose();//垃圾回收
p.Dispose();//垃圾回收
}
private void button2_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clear(BackColor);
g.Dispose();//垃圾回收
}
}
}