用C#的WINFORM做一个简单的用鼠标画画功能。越简单越好,有谁能帮手一下
1个回答
展开全部
新建一个工程默认窗体Form1
写这三个事件
private Point pt1;
bool l = false;
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (l)
{
Graphics g = this.CreateGraphics();
g.DrawLine(new Pen(new SolidBrush(Color.Red)), pt1, new Point(e.X, e.Y));
pt1 = new Point(e.X, e.Y);
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
l = true;
pt1 = new Point(e.X, e.Y);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
l = false;
}
写这三个事件
private Point pt1;
bool l = false;
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (l)
{
Graphics g = this.CreateGraphics();
g.DrawLine(new Pen(new SolidBrush(Color.Red)), pt1, new Point(e.X, e.Y));
pt1 = new Point(e.X, e.Y);
}
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
l = true;
pt1 = new Point(e.X, e.Y);
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
l = false;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询