Back to Devexpress

SimpleButton.CustomDraw Event

windowsforms-devexpress-dot-xtraeditors-dot-simplebutton-850dfc5d.md

latest3.2 KB
Original Source

SimpleButton.CustomDraw Event

Allows you to draw the button manually.

Namespace : DevExpress.XtraEditors

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Appearance")]
public event EventHandler<ButtonCustomDrawEventArgs> CustomDraw
vb
<DXCategory("Appearance")>
Public Event CustomDraw As EventHandler(Of ButtonCustomDrawEventArgs)

Event Data

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

PropertyDescription
BoundsGets button bounds.
InfoGets information about the drawn button.
PainterProvides access to the object that performs paint operations. Inherited from ObjectCustomDrawEventArgs.

The event data class exposes the following methods:

MethodDescription
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.

Remarks

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

csharp
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;
    }
}
vb
Private Sub simpleButton1_CustomDraw(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.ButtonCustomDrawEventArgs)
    If e.Info.State = DevExpress.Utils.Drawing.ObjectState.Hot Then
        e.Cache.FillRectangle(Brushes.Orange, e.Bounds)
        e.DefaultDrawImage()
        e.DefaultDrawText()
        e.Handled = True
    End If
End Sub

See Also

SimpleButton Class

SimpleButton Members

DevExpress.XtraEditors Namespace