Skip to main content
A newer version of this page is available. .

LayoutView.CustomDrawCardBackground Event

Allows you to highlight or manually paint a card’s border and background in a custom manner.

Namespace: DevExpress.XtraGrid.Views.Layout

Assembly: DevExpress.XtraGrid.v18.2.dll

Declaration

[DXCategory("CustomDraw")]
public event LayoutViewCustomDrawCardBackgroundEventHandler CustomDrawCardBackground

Event Data

The CustomDrawCardBackground event's data class is DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCustomDrawCardBackgroundEventArgs.

Remarks

You can handle the CustomDrawCardBackground event to perform the following tasks:

  • Manual element rendering
  • Combining default painting and custom painting
  • Customizing element display information for default rendering

For more information on using custom draw events, see Custom Painting Scenarios.

Example: Provide Custom Card Background by Combining Default Painting and Custom Painting

To fill a card’s background with a custom color, you can first call the DefaultDraw method (which draws a card’s border and background) and then override the card’s background with custom painting by using the Cache.FillRectangle method. The following example fills the focused card’s background with a semi-transparent Red color.


private void layoutView1_CustomDrawCardBackground(object sender, DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCustomDrawCardBackgroundEventArgs e) {
    if (!e.IsFocused) return;
    // Perform default drawing
    e.DefaultDraw();
    using (var highlight = new SolidBrush(Color.FromArgb(25, Color.Red))) {
        // Fill card with semi-transparent color
        e.Cache.FillRectangle(highlight, Rectangle.Inflate(e.Bounds, -1, -1));
    }
}

LayoutView-CustomCardBackground-BackColor.png

Example: Provide Custom Card Background by Changing Display Information for Default Rendering

The following code shows how to customize a card’s display information prior to default painting (the default painting mechanism will be invoked after your CustomDrawCardBackground event handler has been completed, unless you manually call the DefaultDraw method, or set the Handled event parameter to true).

Card elements (including the card border) in LayoutView are painted using corresponding skin elements. A directly specified custom card border color is not in effect, since it is overridden by the skin element. However, you can blend a custom color with the skin element by using the Info.AllowBorderColorBlending event argument. The code below specifies a custom card background color and enables color blending. The actual painting is performed after your CustomDrawCardBackground event handler is completed.


private void layoutView1_CustomDrawCardBackground(object sender, DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCustomDrawCardBackgroundEventArgs e) {
    if (!e.IsFocused) return;
    e.Info.AllowBorderColorBlending = true;
    e.Appearance.BackColor = Color.Blue;
}

Note that this code is particularly useful when highlighting cards without captions (see LayoutViewOptionsView.ShowCardCaption).

LayoutView-CustomCardBackground-ColorBlending.png

See Also