【发布时间】:2015-06-10 02:24:44
【问题描述】:
我有一个面板,其中 AutoScroll 属性为 tru(AutoSize 为 false)。使用变量 Graphics g 我在这个面板上画了一些线。问题是当滚动条出现时,在执行期间创建的所有行都消失了。知道为什么以及一些可能的解决方案吗?
我尝试使用另一个面板来绘制线条,将其背景色设置为透明,但似乎不太好,因为我拥有的其他内容(如文本框等)隐藏在新面板中
这是我的一些代码和一些屏幕截图,希望对您有所帮助! 谢谢
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 是全局队列
【问题讨论】:
-
您将不得不完全重构您的绘图! - 无论您在
Panel(或任何其他控件)上绘制的内容需要在Paint事件中绘制。在创建数据(可能在类级别的变量中)之后,事件绘制方法可以从中工作,例如:e.Graphics.DrawLine(..)你调用Panel.Invalidate() -
一旦你把绘图的东西移到了它所属的地方,你可能需要adapt进行滚动..
标签: c# css .net visual-studio-2010 visual-studio