[RESOLVED] [2005] Graphics Object
Right now I'm drawing multiple things to a form using a graphics object. Because of this, I've got a bit of flickering. I figure I can get rid of the flickering if I can create an offscreen graphics object with mostly the same properties as the form one. How can I do this? Thanks.
Re: [2005] Graphics Object
I have heard of people turning on Double Buffering (setting the Double Buffered Property of the Form to True) to resolve this... not sure if it will be in your case, but something to try...
Re: [2005] Graphics Object
Sorry, that doesn't work. I figure this'll be pretty easy once I figure out how to make a graphics object.
Re: [2005] Graphics Object
Well I had always read that you should not store a Graphics object outside of the scope of the method that its given to. I even found the link to the article I read that specified that, linked below. You can check out this "Beginners Guide to GDI+" to see if that helps at all...
http://www.bobpowell.net/beginnersgdi.htm
Re: [2005] Graphics Object
On second look, that article doesnt really go into what you are looking for. I have read methods where you could call InValidate() only on the control or controls that you are drawing in order for it to only have to update those controls.
I have also found this short article that shows how to use Graphics.FromImage to create a back buffer... this may be similar to what the double buffer property does, but I figured I would put it up anyways...
http://www.developerfusion.co.uk/show/4668/
Re: [2005] Graphics Object
Ok, thanks for the help, I think I can work with the last link you gave.
Re: [RESOLVED] [2005] Graphics Object
Try putting these in the load event of your form:
VB Code:
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
SetStyle(ControlStyles.AllPaintingInWmPaint, True)
Re: [RESOLVED] [2005] Graphics Object
I think what you're looking for is some explanation of how to draw to a memory location, and then to set that onto the screen to avoid flickering.
If you post some example of what you're drawing and when it flickers, we can probably show you how to avoid it. Usually it would involve drawing to a Bitmap object instead of on the form, and then either calling DrawImage to put that on the form, or simply setting the form's backgroundimage to that bitmap.
VB Code:
Dim Bm As New Bitmap(Me.Width, Me.Height) 'Creates a new memory bitmap object with the form's height/width as the size
Dim gr As Graphics = Graphics.FromImage(Bm)
'Your drawing code here, i.e,
gr.Drawline(Pens.Blue,0,0,40,40)
'And then after you're finished the drawings
Me.BackgroundImage = Bm
Bill