I think you will need to draw in the bitmap, then in the OnPaint method draw this bitmap in the window. I will demonstrate in a moment.
As Hans pointed out, in the OnPaint method you set
formGraphics = e.Graphics;
but at the end of the e.Graphics method is placed, so you can no longer use it if your code got to
Engine.Draw(formGraphics);
you will get an exception.
So basically you need to have global
Bitmap buffer = new Bitmap(this.Width, this.Height)
in your asynchronous stream, you will reference your drawing to this bitmap, which you can use
Graphics g=Graphics.FromBitmap(buffer);
To get a graphic, but remember that you must
g.Dispose()
or wrap it in
using (Graphics g=Graphics.FromBitmap(buffer)) {
I'm going to play with him for a few minutes and see if I can get a working sample.
EDIT Here is your working sample. I started a new form and threw a button on it. I changed mainform backgroundimagelayout to none.
I think you need to use .net 4.0 or better, if not using this, let me know that I can change it to suit your version ... I think.
}
General Gray May 23 '12 at 11:15 2012-05-23 11:15
source share