Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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# 切换到选项卡2并返回到选项卡1后,如何在选项卡控件的picturebox中保存图形?_C#_Graphics_Drawing_Tabcontrol_Picturebox - Fatal编程技术网

C# 切换到选项卡2并返回到选项卡1后,如何在选项卡控件的picturebox中保存图形?

C# 切换到选项卡2并返回到选项卡1后,如何在选项卡控件的picturebox中保存图形?,c#,graphics,drawing,tabcontrol,picturebox,C#,Graphics,Drawing,Tabcontrol,Picturebox,我有一个带有两(2)个选项卡的选项卡控件。选项卡1使用Graphics Addline在图片框中绘制图形(图片框是可选的,我可以直接绘制到选项卡)。第二个选项卡打开一个web浏览器。一切正常。我可以在第一个选项卡中绘制图形,但当我切换到第二个选项卡并返回到第一个选项卡时,图形将消失,如果返回到选项卡2,我可以在web浏览器中看到我正在观看的内容。我需要将图纸保留在选项卡1中,以便在返回时可以看到它。下面是我在选项卡1中绘制的代码: private void DataLoaded(ref stri

我有一个带有两(2)个选项卡的选项卡控件。选项卡1使用Graphics Addline在图片框中绘制图形(图片框是可选的,我可以直接绘制到选项卡)。第二个选项卡打开一个web浏览器。一切正常。我可以在第一个选项卡中绘制图形,但当我切换到第二个选项卡并返回到第一个选项卡时,图形将消失,如果返回到选项卡2,我可以在web浏览器中看到我正在观看的内容。我需要将图纸保留在选项卡1中,以便在返回时可以看到它。下面是我在选项卡1中绘制的代码:

private void DataLoaded(ref string strFileName)  //strFileName has the data 
need for the drawing.
{

 Graphics g = this.pictureBox1.CreateGraphics();

 Pen black = new Pen(Color.Black, 5); 

 Pen green = new Pen(Color.Green, 5); 

 List<double> xpoints = new List<double>(); 

 List<double> ypoints = new List<double>();

 g.TranslateTransform(350, 350);

 g.DrawLine(green, new Point(Convert.ToInt32(X1), Convert.ToInt32(Y1)), new  
 Point(Convert.ToInt32(X2), Convert.ToInt32(Y2))); 

 for (int i = 2; i < xpoints.Count(); i++){

            g.DrawLine(black, new Point(Convert.ToInt32(X1), 
            Convert.ToInt32(Y1)), new Point(Convert.ToInt32(X2), 
            Convert.ToInt32(Y2))); 

            X1 = X2;                                            
            Y1 = Y2;                                            

            X2 = xpoints[i];                                    
            Y2 = ypoints[i];                                   

        }// end of for 

}
private void dataload(ref string strFileName)//strFileName包含数据
我需要这幅画。
{
Graphics g=this.pictureBox1.CreateGraphics();
黑色钢笔=新钢笔(颜色:黑色,5);
钢笔绿色=新钢笔(颜色:绿色,5);
List xpoints=新列表();
List ypoints=新列表();
g、 翻译形式(350350);
g、 绘制线(绿色,新点(转换为32(X1),转换为32(Y1)),新
点(转换为32(X2),转换为32(Y2));
对于(int i=2;i

我甚至试着用painteventarg画图,但它根本不起作用。这对我有点帮助,因为当我切换回tab 1并将鼠标移到tab上时,它会再次绘制线条。有人能帮我吗??我甚至试过使用这个.picturebox1.Invalidate(),但什么都没有。正如我所说,我需要的是:在切换到选项卡2后在选项卡1中保留图形,这样当我返回到选项卡1时,线条就在那里了。提前谢谢你的帮助

完成了,我只是用一个位图来绘制,然后用位图设置picturebox图像

我使用的代码如下:

Bitmap image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(image);

// In between all the code required for extracting the data and do the draw.

pictureBox1.Image = image;
不管怎样,感谢看到我的问题并试图回答它的人