-5. As mentioned in the design doc also, double buffering must be used
- by any new controls being added. Whenever a property or method that
- changes the look of the control is called, the bitmap representing
- the control should be updated. The Paint method should only copy
- the bitmap to the screen, and *not* recalculate or paint the control.
- To aid in double-buffering, the Control class provides the
- Control.DeviceContext and Control.ImageBuffer properties.
-
- A typical OnPaint will look like this:
-
- protected override void OnPaint (PaintEventArgs pevent) {
- pevent.Graphics.DrawImage (this.ImageBuffer,
- pevent.ClipRectangle,
- pevent.ClipRectangle,
- GraphicsUnit.Pixel);
- }
-
- The ImageBuffer bitmap is supposed to contain the representation
- of the control, often drawn when a property is set, similar to this:
-
- public Color RectColor {
- set {
- sb.Color = value;
- Redraw ();
- }
- }
-
- internal void Redraw () {
- this.DeviceContext.FillRectangle (sb, this.ClientRectangle);
- }
-
-
-6. Minimize redraws as much as possible by utilizing the clipRectangle