急!谁能提供一个C#的鼠标拖动画直线的程序,完整一些的!谢谢! 10
C#实现的。就像Windows里的绘图程序一样,鼠标拖动时能够动态绘制直线。一定要能完全擦除原来的区域,不要拖动时绘出很多直线!...
C#实现的。就像Windows里的绘图程序一样,鼠标拖动时能够动态绘制直线。一定要能完全擦除原来的区域,不要拖动时绘出很多直线!
展开
展开全部
在一个窗体中,拖入pictureBox控件,我这里命名为pictureBox1,并且把它的背景色改为white
private Point p1; //记录初始位置
//鼠标按下后才会触发这个鼠标移动事件
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
using (Graphics g = pictureBox1.CreateGraphics())
{
g.Clear(Color.White);
g.DrawLine(Pens.Red, p1, e.Location);
}
}
//鼠标按下时
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
p1 = e.Location;
}
//鼠标放开后
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
this.pictureBox1.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
}
private Point p1; //记录初始位置
//鼠标按下后才会触发这个鼠标移动事件
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
using (Graphics g = pictureBox1.CreateGraphics())
{
g.Clear(Color.White);
g.DrawLine(Pens.Red, p1, e.Location);
}
}
//鼠标按下时
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
p1 = e.Location;
}
//鼠标放开后
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
this.pictureBox1.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询