简体   繁体   English

切换到选项卡2并返回到选项卡1后,如何将图形绘图保留在选项卡控件的图片框中?

[英]How to kept a graphic drawing in a picturebox on a tab control after switching to tab 2 and return to tab 1?

I have a Tab Control with two (2) Tabs. 我有一个带有两(2)个标签的标签控件。 The Tab 1 does a drawing in a picture box (the picture box is optional, I can draw directly to the tab) using Graphics Addline. 选项卡1使用图形添加线在图片框(图片框是可选的,我可以直接绘制到该标签)中绘制图形。 The second tab opens a web browser. 第二个选项卡打开Web浏览器。 Everything is working fine. 一切正常。 I can make the drawing in the first tab but when I switch to the second tab and return to the first tab, the drawing disappear and if I return to tab 2 I can see what I was watching in the web browser. 我可以在第一个选项卡中制作图形,但是当我切换到第二个选项卡并返回第一个选项卡时,图形消失了,如果返回到选项卡2,我可以在Web浏览器中看到正在观看的内容。 I need to kept the drawing in the tab 1 so when I return to it I can see it. 我需要将图形保留在选项卡1中,以便在返回该图形时可以看到它。 Here is the code I'm using to draw in the tab 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 

}

I even tried to do the drawing using the painteventarg but its not working at all. 我什至尝试使用painteventarg进行绘制,但它根本无法正常工作。 It helped me a bit because when I change back to the tab 1 and move the mouse over the tab it draws again the lines. 这对我有所帮助,因为当我回到选项卡1并将鼠标移到选项卡上时,它会再次绘制线条。 Can anyone help me with this?? 谁能帮我这个?? I even tried using this.picturebox1.Invalidate() but nothing. 我什至尝试使用this.picturebox1.Invalidate()但什么也没有。 Like I said, what I need is: Preserve the drawing in tab 1 after switching to tab 2 so when I returned to tab 1 the lines are there. 就像我说的,我需要的是:切换到选项卡2后,将图形保留在选项卡1中,这样当我返回选项卡1时,线条就在那里了。 Thanks in advance for the help!!!. 先谢谢您的帮助!!!。

Its done, I just used a Bitmap to draw to it and the set the picturebox image with the bitmap. 完成后,我只使用了位图绘制并使用位图设置了图片框图像。

The code I used is as follows: 我使用的代码如下:

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;

Thanks anyway to whoever saw my question and try to answer it. 无论如何,感谢所有看到我的问题并尝试回答它的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM