P
Peter Webb
When I started my current extremely graphics intensive project, I ignored
advice in this ng to use the Paint method, and used the alternate
CreateGraphics approach. I thought there were some good reasons for that,
which I won't go into.
Anyway, there has always been one tiny bug that has annoyed me - the code
that draws the initial graphic image into PictureBox1 will only work if wire
it up to a button, it doesn't actually do anything if I put into Form1 load.
I only see the black background. On a button, it works fine, but I don't
want the user to have to press a "go" button.
Through the debugger, I noticed that all the graphics commands executed
before the Form actually fully loaded. So I moved the routine to draw the
initial graphic into pictureBox1_Paint method. I cheated and put a condition
around it so it only fired off once at the start. No difference. Then I put
in a thread.sleep(1000), after the draw in the Paint method, and noticed a
strange thing - the image was shown for 1000 milliseconds, then disappears.
If I do the same thing explicitly on a button click, it doesn't disappear.
I am now in a bit of a mess. My only real problem was that the initial
graphic in the pictureBox would display on a button click, but not on simply
loading Form1. It looked like a timing problem, but neither DoEvents or
Thread.Sleep solves it. Is there some simple way of solving my original
problem? Can anybody tell me what is going on?
advice in this ng to use the Paint method, and used the alternate
CreateGraphics approach. I thought there were some good reasons for that,
which I won't go into.
Anyway, there has always been one tiny bug that has annoyed me - the code
that draws the initial graphic image into PictureBox1 will only work if wire
it up to a button, it doesn't actually do anything if I put into Form1 load.
I only see the black background. On a button, it works fine, but I don't
want the user to have to press a "go" button.
Through the debugger, I noticed that all the graphics commands executed
before the Form actually fully loaded. So I moved the routine to draw the
initial graphic into pictureBox1_Paint method. I cheated and put a condition
around it so it only fired off once at the start. No difference. Then I put
in a thread.sleep(1000), after the draw in the Paint method, and noticed a
strange thing - the image was shown for 1000 milliseconds, then disappears.
If I do the same thing explicitly on a button click, it doesn't disappear.
I am now in a bit of a mess. My only real problem was that the initial
graphic in the pictureBox would display on a button click, but not on simply
loading Form1. It looked like a timing problem, but neither DoEvents or
Thread.Sleep solves it. Is there some simple way of solving my original
problem? Can anybody tell me what is going on?