winform在picturebox中画图,最小化或者刷新后消失的问题 5
画图的代码如下:privatePointp1,p2;//定义两个点(启点,终点)privatestaticbooldrawing=false;//设置一个启动标志priv...
画图的代码如下:
private Point p1, p2;//定义两个点(启点,终点)
private static bool drawing=false;//设置一个启动标志
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{ p1 = new Point(e.X, e.Y);
p2 = new Point(e.X, e.Y);
drawing = true; }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
drawing = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{Graphics g = pictureBox1.CreateGraphics();
if(e.Button ==MouseButtons.Left)
{
if (drawing)
{
//drawing = true;
Point currentPoint = new Point(e.X, e.Y);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//消除锯齿
g.DrawLine(new Pen(Color.Blue, 2), p2,currentPoint);
p2.X = currentPoint.X;
p2.Y = currentPoint.Y;
} } }
或者不用此代码也行,我的目的就是可以在我picturebox显示的图片上可以自由写画 展开
private Point p1, p2;//定义两个点(启点,终点)
private static bool drawing=false;//设置一个启动标志
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{ p1 = new Point(e.X, e.Y);
p2 = new Point(e.X, e.Y);
drawing = true; }
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
drawing = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{Graphics g = pictureBox1.CreateGraphics();
if(e.Button ==MouseButtons.Left)
{
if (drawing)
{
//drawing = true;
Point currentPoint = new Point(e.X, e.Y);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//消除锯齿
g.DrawLine(new Pen(Color.Blue, 2), p2,currentPoint);
p2.X = currentPoint.X;
p2.Y = currentPoint.Y;
} } }
或者不用此代码也行,我的目的就是可以在我picturebox显示的图片上可以自由写画 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询