我有一个面板,AutoScroll属性为tru(AutoSize为false)。使用变量Graphics g我在此面板上绘制一些线条。问题是当ScrollBars出现时,执行期间创建的所有行都消失了。知道为什么和一些可能的解决方案??
我尝试使用另一个面板,我可以绘制线条,将背景设置为透明,但似乎不太好,因为其他东西我喜欢文本框等隐藏在新面板中
以下是我的一些代码和一些截图,希望他们能提供帮助! 谢谢
private void fwd_exmem_hazard()
{
int poss = 0;
int poss2 = poss+1;
List<mystruct> pipe = new List<mystruct>();
pipe = queue1.ToList();
while (poss2 < fwd1_list.Count)
{
try
{
if (((fwd1_list[poss].cycle == 3) && (fwd1_list[poss].rd == fwd1_list[poss2].rs) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0))
|| (fwd1_list[poss].cycle == 3 && (fwd1_list[poss].rd == fwd1_list[poss2 + 1].rs) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0)))
{
Graphics g; g = panel3.CreateGraphics();
Pen pen = new Pen(Color.Red);
Point p1 = new Point(pipe[poss].location.X+30, pipe[poss].location.Y);
Point p2 = new Point(pipe[poss2].location.X-10, pipe[poss2].location.Y);
g.DrawLine(pen,p1, p2);
fwd_count++;
}
if (((fwd1_list[poss].cycle == 3) && (fwd1_list[poss].rd == fwd1_list[poss2].rt) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0))
|| (fwd1_list[poss].cycle == 3 && (fwd1_list[poss].rd == fwd1_list[poss2 + 1].rt) && (fwd1_list[poss].reg_write) && (fwd1_list[poss].rd != 0)))
{
Graphics g; g = panel3.CreateGraphics();
Pen pen = new Pen(Color.Orange);
Point p1 = new Point(pipe[poss].location.X+30, pipe[poss].location.Y);
Point p2 = new Point(pipe[poss2].location.X-10, pipe[poss2].location.Y);
g.DrawLine(pen, p1, p2);
fwd_count++;
}
poss++; poss2++;
}
catch { break; }
}
}
mystruct是我创建的自定义结构,queue1是一个全局队列
答案 0 :(得分:0)
这就发生了,因为当面板刷新时会调用paint事件并从头开始重绘,因此你的行会消失,所以你需要将你的代码放在Panel Paint事件中。