
展开全部
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CSharpTemp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Controls.Add(new MyControl() { Dock = DockStyle.Fill });
}
}
class Line
{
protected List<Point> points = new List<Point>();
public void Add(Point p)
{
points.Add(p);
}
public void Draw(Graphics g, Pen pen)
{
if (points.Count >= 2)
g.DrawLines(pen, points.ToArray());
}
}
class MyControl : Control
{
protected List<Line> lines = new List<Line>();
public MyControl()
{
DoubleBuffered = true;
}
protected override void OnMouseDown(MouseEventArgs e)
{
Line line = new Line();
line.Add(e.Location);
lines.Add(line);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
lines.Last().Add(e.Location);
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
foreach (Line l in lines)
l.Draw(e.Graphics, Pens.Black);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询