Back to Devexpress

How to: Supply Custom Error Icon for Editor

windowsforms-9480-controls-and-libraries-editors-and-simple-controls-examples-how-to-supply-custom-error-icon-for-editor.md

latest1.8 KB
Original Source

How to: Supply Custom Error Icon for Editor

  • Oct 25, 2019

The following example shows how to supply a custom error icon via the DXErrorProvider.GetErrorIcon event. In this event, a custom icon ( ) is provided when the error type is set to ErrorType.User1.

The result is illustrated below:

csharp
using DevExpress.XtraEditors.DXErrorProvider;

DXErrorProvider.GetErrorIcon += new GetErrorIconEventHandler(DXErrorProvider_GetErrorIcon);

// Associate an error of the User1 error type with a buttonEdit1 control.
dxErrorProvider1.SetError(buttonEdit1, "Error", ErrorType.User1);

//...

Image icon = Image.FromFile(@"C:\arrow.png");
// Provide an error icon for the User1 error type.
void DXErrorProvider_GetErrorIcon(GetErrorIconEventArgs e) {
    if (e.ErrorType == ErrorType.User1) {
        e.ErrorIcon = icon;
    }
}
vb
Imports DevExpress.XtraEditors.DXErrorProvider

AddHandler DXErrorProvider.GetErrorIcon, AddressOf DXErrorProvider_GetErrorIcon

'Associate an error of the User1 error type with a buttonEdit1 control.
DxErrorProvider1.SetError(ButtonEdit1, "Must be between 0 and 100", ErrorType.User1)

'...

Dim _icon As Image = Image.FromFile("C:\arrow.png")
' Provide an error icon for the User1 error type.
Private Sub DXErrorProvider_GetErrorIcon(ByVal e As _
  DevExpress.XtraEditors.DXErrorProvider.GetErrorIconEventArgs)
    If e.ErrorType = ErrorType.User1 Then e.ErrorIcon = _icon
End Sub