Jeroen,
The way that windows works is that there is a loop which does nothing
but process messages. One of these messages is a command which indicates
that the window should repaint itself. When this happens, in .NET usually
the OnPaint method of a Control class is called (which is exposed in a Form,
because Form extends Control).
Now, if you call a method to paint a bitmap in a button click, the image
will appear, but the next time the window gets a notification to re-paint
itself, it will dissapear, because there are no instructions to keep the
bitmap painted (you did it once in the button click, and the OnPaint method
or the Paint event handler doesn't have any knowledge of your bitmap).
The paint routine is really a state machine. You should override
OnPaint. In it, you call the base implementation. Then, you check the
state. If a bitmap exists to paint, then paint it, otherwise, do nothing.
Now, in your button click (or wherever you set the bitmap), you would
load the picture, and then store it where the OnPaint method can access it.
Then, you would call the Invalidate method. This will send a message to
your window to repaint itself, at which point, your custom code in OnPaint
will paint the loaded bitmap.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Jeroen Ceuppens said:
No i didn't, what do you mean by implementing?
A sort of repaint?
when
you