windowsforms-devexpress-dot-xtragrid-dot-views-dot-layout-dot-layoutview-99ac38a9.md
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.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
[DXCategory("CustomDraw")]
public event LayoutViewCustomDrawCardBackgroundEventHandler CustomDrawCardBackground
<DXCategory("CustomDraw")>
Public Event CustomDrawCardBackground As LayoutViewCustomDrawCardBackgroundEventHandler
The CustomDrawCardBackground event's data class is DevExpress.XtraGrid.Views.Layout.Events.LayoutViewCustomDrawCardBackgroundEventArgs.
You can handle the CustomDrawCardBackground event to complete the following tasks:
For more information on using custom draw events, see Custom Painting Scenarios.
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));
}
}
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).
See Also