2005-08-10 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / Managed.Windows.Forms / Guidelines
index 260b911aa21bd2d9d58fbd5aa3e3388c1464265e..967ef6c7f6d4c8f939567b7a63c39f2cc41b6477 100644 (file)
@@ -18,58 +18,41 @@ guidelines are for the sake of consistency.
 
 4. When you implement the drawing method for a control in a theme, it
    should make call to ControlPaint class methods and System.Drawing
-   classes. If it is not possible to implment a control's draw method
+   classes. If it is not possible to implement a control's draw method
    under these restrictions and you need some functionality from
    XplatUIDriver, please let us know. We will try to enhance the
    driver, if *really* required.
 
-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 
+5. Minimize redraws as much as possible by utilizing the clipRectangle 
    when possible.
 
-7. Setting the size of a control raises a resize event even if the
+6. Setting the size of a control raises a resize event even if the
    control size is same. Be careful is setting the size and it's better
    to avoid changing the control size as much as possible. Wherever
    possible try scaling the control bitmap as per the size needs.
 
-8. Make sure to call the base class event methods when overriding them.
+7. Make sure to call the base class event methods when overriding them.
 
-9. Define regions in your code, as it makes it easy to browse the code
-   in the editors which can collapse/expand regions.
+8. Define regions in your code, as it makes it easy to browse the code
+   in the editors which can collapse/expand regions. Also, keep the 
+   methods and properties sorted alphabetically.
 
-10. Last but not the least, please let others on the mono-winforms-list
+9. Last but not the least, please let others on the mono-winforms-list
     know about your work, so that duplication can be avoided.
+    
+10. Theme.cs provides Pen and Brush caching. This allows to share
+    the same brushes and pens between different controls and also to avoid
+    to create and destroy them in every draw operation. You should not create
+    Brushes or Pens directly, you should ask the Resource Pool for them. For
+    example, instead of:
+
+    new SolidBrush(button.BackColor);
+    
+    you should use:
+    
+    ResPool.GetSolidBrush (button.BackColor);
+    
+    Look at SystemResPool class for more details.
 
 Happy hacking!