写了一个用鼠标实现画图的程序:
private System.Drawing.Point p1, p2;//定义两个点(启点,终点)
private static bool drawing = false;
private void draw_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
p1 = new System.Drawing.Point(e.X, e.Y);
p2 = new System.Drawing.Point(e.X, e.Y);
drawing = true;
}
private void draw_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
drawing = false;
}
private void draw_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
Graphics g = pictureBox1.CreateGraphics();
if (e.Button == MouseButtons.Left)
{
if (drawing)
{
//drawing = true;
System.Drawing.Point currentPoint = new System.Drawing.Point(e.X, e.Y);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//消除锯齿
g.DrawLine(new System.Drawing.Pen(System.Drawing.Color.Blue, 2), p2, currentPoint);
p2.X = currentPoint.X;
p2.Y = currentPoint.Y;
}
}
}
实现功能如下:

我现在想要把我鼠标写画的部分(即c#)可以用鼠标自由的拖动到任何位置,怎么才能实现。。。
------解决思路----------------------
你需要用一个数据结构,比如List<List<Point>>记录下你绘制的线条(每个线条由点构成)
鼠标拖动的时候判断所处的是哪个线条,将它对应的坐标全部减去或者加上一个值
Paint事件只管画图