Surfaces?

  • Thread starter Thread starter mutant
  • Start date Start date
M

mutant

Guest
Is it possible to have like 2 layers of graphics in GDI+? I have some image that stays in the background and i dont wish to have to draw it every time paint is fired because i can see the picture get flicker.
 
If you use double-buffering when you draw your control it shouldnt flicker. There isnt a "two layer" thing as you described.
 
Thats weird, i can get the double buffering to work with shapes, but it doesnt with images :( . Could show me an example for images or point me to some source where I could maybe find a tutorial or some explanation? Couldnt find any.
 
Ive never had a problem using double-buffering when drawing images. Can you post a sample that illustrates the problem?
 
I found a sample on internet.
Code:
        Dim bmp As New Bitmap(30, 30)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.DrawImage(New Bitmap("image.jpg"), 0, 0)
        Dim x As Integer
        For x = 0 To 5
        e.Graphics.DrawImage(bmp, x * 30, 0)
        Next
Is this correct?
 
That works fine for me - I take it youve enabled the DoubleBuffer and AllPaintingInWmPaint styles for the form/control? Remember you dont have to do anything yourself to get double buffering to work, once youve set those two styles .NET does the rest.

As a side note, that code is nasty - it doesnt clean up any of the resources it uses.
 
Thats funny, no of the articales said that I only need to setstyle to double buffer and .NET will do the rest, they told me to draw images like i showed before. Oh well, at least now its working all right :)
 
Back
Top