如何在带有图像的面板上绘制点

时间:2011-12-08 07:20:40

标签: c# winforms

我有一个名为dPanel的面板。我用该图像命名dImage.Now设置该面板的backgroundImage我想在面板上绘制点,换句话说我想用鼠标为面板着色。我希望能够将图形和图像保存在一起后来。我的代码执行此操作但图片在绘图期间亮起并且非常慢。这是我的代码:

 private void drawP_MouseDown(object sender, MouseEventArgs e)
    {
        if (!drawbool)
        {
            dStartPoint = e.Location;
            drawbool = true;
        }
        drawP.Invalidate();
    }
 private void drawP_MouseMove(object sender, MouseEventArgs e)
    {
        if (drawbool)
        {
            dStartPoint = e.Location;
            drawP.Invalidate();
        }
    }
 private void drawP_MouseUp(object sender, MouseEventArgs e)
    {
        if (drawbool)
        {
            drawbool = false;
        }
    }
  private void drawP_Paint_1(object sender, PaintEventArgs e)
    {
        if (drawbool)
        {
            int dStartX = dStartPoint.X;
            int dStartY = dStartPoint.Y;
            e.Graphics.DrawEllipse(dP, dStartX, dStartY, 2, 2);
            Bitmap dPPB = new Bitmap(drawP.Width, drawP.Height);
            drawP.DrawToBitmap(dPPB, new Rectangle(0, 0, drawP.Width, drawP.Height));
            drawP.BackgroundImage = (Image)dPPB;
        }
    }

Whani的解决方案?提前谢谢。

1 个答案:

答案 0 :(得分:1)

查看关于在面板上绘图的这个很好的示例:Painting on a Panel

稍后您可以通过调用面板的方法 DrawToBitmap 来保存您的绘图。