Back to Devexpress

Custom Painting

windowsforms-467-controls-and-libraries-vertical-grid-appearance-and-custom-painting-custom-painting.md

latest4.7 KB
Original Source

Custom Painting

  • Apr 11, 2022
  • 3 minutes to read

All DevExpress .NET Windows Forms controls use Appearances (the AppearanceObject objects) to customize their look and feel. The vertical grid controls (VGridControl and PropertyGridControl) provide both design time and runtime facilities for customizing the appearance of their visual elements. This implies modifying attributes such as the background and foreground colors, background images, font settings, etc. The appearance settings used to paint the grid’s elements can be customized in a number of ways which are listed in the Appearance and Conditional Formatting document.

If the appearance customization techniques provided don’t suit your needs, you can handle the custom draw events.

CUSTOM PAINTING BASICS

You can paint elements manually by handling vertical grid events, specifically designed for this purpose. Each event is used to paint the elements of a specific type and fires before an individual element is painted. For instance, the VGridControlBase.CustomDrawTreeButton event can be used to paint tree buttons displayed within the headers of parent rows. It fires for each individual tree button every time the button needs to be painted (e.g. when the row becomes visible or when it is expanded or collapsed). Thus, you can provide a custom appearance for all types of elements in all their states.

The image below shows an example of using the custom painting feature.

The custom draw events can be handled for the following purposes:

  • To paint the elements manually.

  • To paint the elements using the default mechanism but with modified appearance settings.

Custom draw events are raised before the grid elements are painted. These events have different sets of parameters since they are designed to paint different elements. However, some parameters are common to all events. These parameters are listed below.

ParameterDescription
CustomDrawEventArgs.GraphicsGets the System.Drawing.Graphics object which represents the painting surface. This object provides a number of methods that can be used to paint text, images and geometrical primitives (such as rectangles, circles, polylines, etc). Use these methods to paint the processed element’s content in the manner you want.
CustomDrawEventArgs.BoundsGets the bounding rectangle of the element being painted. Use this parameter to determine where to paint.
CustomDrawEventArgs.CacheGets an object which specifies the storage for the most used pens, fonts and brushes.
CustomDrawEventArgs.HandledSpecifies whether the event is handled. If custom drawing is implemented and the Handled property’s value is set to false , all the custom drawing performed will be overwritten by the default painting mechanism using the appearance settings. Set this property to true to prevent the default painting mechanism from clearing any custom drawing.
CustomDrawEventArgs.AppearanceGets the appearance settings used to paint an element.

See the following documents for a list of the elements that can be custom painted and examples:

See Also

How to get colors that correspond to the currently used skin

How to obtain the color of a particular control's element when skins are used

How to get skin images at runtime