OnPaintBackground Vs OnPaint

Something I wanted all you guys should now...

I realized when creating custom controls with the .NET CF, and overriding OnPaint method, it is quite useful to do this:

- Override the OnPaintBackground and remove base.OnPaintBackground - The OnPaintBackground does not rely on the eventing mechanism (coz there is nothing like a PaintBackground event), hence drawing turns out to be faster and fluent

- use double buffering, loads of tutorials on Google

- Do as much drawing possible as you can in OnPaintBackground and leave the most dynamic parts of the UI to OnPaint

- Create your Graphics object early in the the OnResize override

- Draw less often, dispose whenever you draw. Use the using clause, makes code look neater, cleaner and easier to comprehend, and of course it saves all the tidbits of disposing stuff


These helped me quite a bit

Comments

Popular Posts