如何在图片框中绘图,以便绘图不会消失?

时间:2015-02-23 13:28:54

标签: c# winforms graphics controls picturebox

我看到了类似的问题here

但我不明白如何解决我的问题。当我移动,最小化或覆盖窗体的窗口时,绘制消失。

我的部分代码是:

private void timer1_Tick(object sender, EventArgs e) {
Pen pen = new Pen(Color.Red, 2);
Pen pen2 = new Pen(Color.Green, 2);
long i; //this value changes each tick and is set by another method

picturebox1.CreateGraphics().DrawLine(pen, 0 + i, 0, 0 + i, 10); 
picturebox1.CreateGraphics().DrawLine(pen2, 0 + ((i*2)/1.2), 0, 0 + ((i*2)/1.2), 50); }

我需要代码在timer1_Tick()方法中,因为它必须在每个tick处绘制。 我使用OnPaint()方法及其覆盖吗?如果是的话,如何在我的场景中做到这一点?

0 个答案:

没有答案