0

I'm new in this forum, and my english is not perfect, so i want to excuse if my question isn't writen good.

I'm making a painting program with C# and all is perfect expect one problem. When i'm drawing a line, or rectangle or elipse, when the mouseMove event is called the old shapes is drawed too.

How to draw a shape with mouseMove event and the old shapes to not been drawed.

Here is part of my code for more clarification.

//---Variables declared by the Prgrammer---//
//'parent' is variable that take the MdiParent
//'mouseIsDown' is boolean variable
//'startPoint' and 'endPoint' are Point Varables
//'pen' is Pen variable that is configured eralier
//'graphic' is pictureBox in the same form.

private void pbx_MouseDown(object sender, MouseEventArgs e)
    {
        if (parent.btnLine.Checked)
        {
            mouseIsDown = true;
            startPoint = new Point(e.X, e.Y);
        }
    }

    private void pbx_MouseMove(object sender, MouseEventArgs e)
    {
        if (mouseIsDown == true && parent.btnLine.Checked)
        {
            pen = new Pen(parent.btnPreview.BackColor, 12);
            endPoint = new Point(e.X, e.Y);
            graphic.DrawLine(pen, startPoint, endPoint);
        }
    }

    private void pbx_MouseUp(object sender, MouseEventArgs e)
    {
        mouseIsDown = false;
    }

Please help me. This is a big problem for me. Thanks.


Please help me, i'm waiting 2 days. When i'm making a new drawing to the graphic object, the old graphic is deleted.

I try the graphic.Save() method, but has not give me right result.

How to make the drawings to saty when i'm making another graphic?

4

1 回答 1

0

当您使用图片框时,您可以使用Invalidate()方法。

于 2012-04-21T08:32:04.537 回答