17,741
社区成员
发帖
与我相关
我的任务
分享
private void picBxSketch_Paint(object sender, PaintEventArgs e)
{
int distance = 40;
Pen linePen = new Pen(Color.Red);
for (int i = 1; i <= 4; i++) {
//初始的四条横线,横线建的间距大一些
e.Graphics.DrawLine(linePen, new Point(85, (distance + 10) * i + 30), new Point(240, (distance + 10) * i + 30));//横线
e.Graphics.DrawLine(linePen, new Point(distance * i + 65, 60), new Point(distance * i + 65, 250));//竖线
}}
class drawPoints:Form
{
private Point m_Start;
private List <Point> m_ListPoint;
public drawPoints()
{
this.DoubleBuffered = true;
m_ListPoint = new List <Point> ();
}
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
this.m_Start = e.Location;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (e.Button == MouseButtons.Left)
{
this.m_ListPoint.Add(e.Location);
this.m_Start = e.Location;
this.Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
for (int i = 0; i < this.m_ListPoint.Count-1; i++)
{
e.Graphics.DrawLine(SystemPens.ControlText, this.m_ListPoint[i], this.m_ListPoint[i + 1]);
}
}
}