It's a bit more fundamental than that, I'm afraid.
When you create a Graphics context and draw something, the drawing is not preserved - it is transitory and will survive until the next time Windows decides the control needs to be re-drawn. Which in your case will be immediately after your method ends...:laugh:
At which point the lines you have drawn will be erased to prepare the drawing surface fro the controls to drawn themselves.
So, there are two things you must do:
1) First, if you create a Graphics object you are responsible for Disposing of it - failing to do that (as in your code above) will cause cause problems in teh long run, because Graphics contexts are scarce resources and you will run out of them a long time before the Garbage Collector gets round to deleting them for you. At this point you program will crash. If you ever create a scarce resource, enclose it in a
using
block:
using (Graphics mp = pnlOverview.CreateGraphics())
{
mp.DrawLine(OVTable, x, 40, x, 100);
y++;
x += 8;
}
2) Don't do it that way - you need to handle the Paint event for the panel and draw the lines in there. Just add the event handler when you construct the panel, and move the
while
loop into that, replacing the
mp
with
e.Graphics
and you should be fine.