0

我正在 Windows Mobile 智能设备应用程序的图片框上绘制图表。该图运行良好,但之后立即消失。

我用了这条线:

this.Invoke(new EventHandler(picture2_show));

和我的绘画方法:

private void picture2_show(object sender, EventArgs e)
{
    using (Graphics objGraphics = this.pictureBox2.CreateGraphics())
    {
        Pen redpen = new Pen(Color.Red, 1);
        int picBoxWidth = pictureBox2.Size.Width;
        int picBoxHeight = pictureBox2.Size.Height;
        int halfWidth = pictureBox2.Size.Width / 2;
        int halfHeight = pictureBox2.Size.Height / 2;

        Graphics objGraphic = this.pictureBox2.CreateGraphics();

        objGraphic.DrawLine(redpen, 0, 0, 0, picBoxHeight);
        objGraphic.DrawLine(redpen, 0, picBoxHeight - 1, picBoxWidth, picBoxHeight - 1);
        //Rectangle first = new Rectangle(0, halfHeight, picBoxWidth, halfHeight);

        Pen bpen = new Pen(Color.LawnGreen, 3);
        for (int i = 0; i < array.Length - 1; i++)
        {
            objGraphic.DrawLine(
                bpen, 
                pictureBox2.Size.Width * i / array.Length,
                pictureBox2.Size.Height - array[i],
                pictureBox2.Size.Width * (i + 1) / array.Length,
                pictureBox2.Size.Height - array[i + 1]);
        }
    }
}

图片框仍然存在,但是如何使图形不消失?

非常感谢您的帮助!

4

1 回答 1

1

Paint您需要在图片框的事件中绘制图表,使用e.Graphics.
要强制它重绘,请调用pictureBox2.Invalidate().

不要在 上绘制CreateGraphics(),因为下次绘制控件时它将被擦除。

于 2011-04-21T18:00:57.853 回答