Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使图片保留在Picturebox上?_C#_Windows Mobile_Picturebox_Graphing - Fatal编程技术网

C# 如何使图片保留在Picturebox上?

C# 如何使图片保留在Picturebox上?,c#,windows-mobile,picturebox,graphing,C#,Windows Mobile,Picturebox,Graphing,我正在Windows Mobile智能设备应用程序的图片盒上绘制图形。该图运行良好,但随后立即消失 我用了这句话: this.Invoke(new EventHandler(picture2_show)); 我的绘画方法是: private void picture2_show(object sender, EventArgs e) { using (Graphics objGraphics = this.pictureBox2.CreateGraphics()) {

我正在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]);
        }
    }
}
private void picture2\u show(对象发送方,事件参数e)
{
使用(Graphics objGraphics=this.pictureBox2.CreateGraphics())
{
Pen redpen=新笔(颜色:红色,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();
对象绘制线(红色,0,0,0,picBoxHeight);
对象绘图线(红色,0,picBoxHeight-1,picBoxWidth,picBoxHeight-1);
//矩形优先=新矩形(0,半高,picBoxWidth,半高);
笔bpen=新笔(Color.LawnGreen,3);
for(int i=0;i
picturebox保持不变,但如何使图形不消失


非常感谢您的帮助

您需要使用
e.Graphics
在picturebox的
Paint
事件中绘制图形
要强制重新绘制,请调用
pictureBox2.Invalidate()


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

非常感谢!这真的很有帮助!不客气。您应该通过单击空心复选框来接受此答案。