Double buffering problem.

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
Double buffering problem.[Resolved]

Hi thanks for taking the time to read this. Ok, i am developing my own user control from scratch . Its going to be a simple button that has as few properties. I just have one very small problem that i cant seem to get around.
When i turn on double buffering on in my control it causes my control not to be displayed at run or design time, i can't figure this one out. It seems to work if i inherit from another control such as the panel but not if i directly inherit from user control and do all the painting myself.
Please can anyone help as i'm starting to lose heart. Hope this enough info to give a response, if not please ask and i'll try to be clearer.
 
Last edited:
Yea no problem, here's my code....

Just after the 'initialize component' in the collapsed region, i am using

SetStyle(Controlstyles.doublebuffering,true)
SetStyle(Controlstyles,AllPaintinginWMpaint,True)
SetStyle(Controlstyles,UserPaint, True)
 
Well that looks good to me, guessing its mean't to be doublebuffer rather than doublebuffering.. I assume you're overriding OnPaint? Bit stumped to be honest, sorry! Shall reply if I think of anything.
 
No actually, i'm writing in the 'On Paint' event. I didn't think i needed to override the paint event seeing as it's being painted from scratch, or have i got that horribly wrong. And yes i did mean 'doublebuffer' still a bit new to all this GDI+, sorry.
 
Hey,

Ah, makes sense now..

When you specify AllPaintinginWMPaint it means you have to draw everything yourself by overriding OnPaint, try removing AllPaintinginWMPaint to see if this is the problem.
 
Do you have any thing in your control other than what you're drawing?
If you put the AllPainting.... back in then you need to to override ONPaint and call Me.Invalidate every time you want it to update.. I've not been using GDI+ for very long either so I'm afraid I'm no expert and I'm not sure how to use double buffering when you have controls on the control.. This is straight out of some code of mine for a text scroller to show the override..

VB.NET:
 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        If Redraw = True Then
            ga = e.Graphics
            ga.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            ga.DrawString(_MyText, fo, Brushes.Black, widthX, heightY)
        End If
    End Sub
 
Ok, i get what you mean now, problem was i didn't really understan what ...

Allpaintingin.... actually ment!!! So thanks loads for the advice and i'll try what you have suggested. Thanks again. Ill post back tomorrow if i get it cracked.
 
Back
Top