Skip to main content
All docs
V24.1

SimpleButton.CustomDraw Event

Allows you to draw the button manually.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DXCategory("Appearance")]
public event EventHandler<ButtonCustomDrawEventArgs> CustomDraw

Event Data

The CustomDraw event's data class is ButtonCustomDrawEventArgs. The following properties provide information specific to this event:

Property Description
Bounds Gets button bounds.
Cache Provides access to the drawing surface and a cache of pens, fonts, and brushes. Inherited from ObjectCustomDrawEventArgs.
Graphics Provides access to the drawing surface. Inherited from ObjectCustomDrawEventArgs.
Handled Gets or sets whether the event is handled and prevents the default draw operation from being performed. Inherited from ObjectCustomDrawEventArgs.
Info Gets information about the drawn button.
IsDefaultDrawInProgress Inherited from ObjectCustomDrawEventArgs.
Painter Provides access to the object that performs paint operations. Inherited from ObjectCustomDrawEventArgs.

The event data class exposes the following methods:

Method Description
DefaultDraw() Inherited from ObjectCustomDrawEventArgs.
DefaultDrawBackground() Draws the button background in its default appearance.
DefaultDrawImage() Draws the button image in its default appearance.
DefaultDrawText() Draws button text in its default appearance.
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>) Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from ObjectCustomDrawEventArgs.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>) Paints the required HTML template inside an element that raised this event. Inherited from ObjectCustomDrawEventArgs.

Remarks

The following code snippet handles the CustomDraw event to change the button’s hovered background:

WinForms SimpleButton - CustomDraw Event

void simpleButton1_CustomDraw(object sender, DevExpress.XtraEditors.ButtonCustomDrawEventArgs e) {
    if(e.Info.State == DevExpress.Utils.Drawing.ObjectState.Hot) {
        e.Cache.FillRectangle(Brushes.Orange, e.Bounds);
        e.DefaultDrawImage();
        e.DefaultDrawText();
        e.Handled = true;
    }
}
See Also