How to set the ErrorProvider icon for software for all controls

We use derived class forms with one base class for our software.

In derived forms, we make extensive use of DataBinding to work with our BusinessObjects, all implementing IDataErrorInfo, throwing custom error messages to false inputs in the GUI using ErrorProviders.

Now I’m looking for a way to implement a function in the base class of the form, to get all the ErrorProvider-Form components in the form and set the IconAlignment for each control on the form to the left (since the right is a space).

Any hints are welcome ...

Code for setting the icon:

private void SetErrorProviderIconAlignment(ErrorProvider errorProvider, Control control)
{
    errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);

    foreach (Control subControl in control.Controls)
    {
        SetErrorProviderIcon(errorProvider, subControl);
    }
}
+3
source share
1

ErrorProvider, / IconAlignment.

.

[ToolboxBitmap(typeof(ErrorProvider))]
[ProvideProperty("IconAlignment", typeof(Control))]
public class MyErrorProvider : ErrorProvider
{
    #region Base functionality overrides

    // We need to have a default that is explicitly different to 
    // what we actually want so that the designer generates calls
    // to our SetIconAlignment method so that we can then change
    // the base value. If the base class made the GetIconAlignment
    // method virtual we wouldn't have to waste our time.
    [DefaultValue(ErrorIconAlignment.MiddleRight)]
    public new ErrorIconAlignment GetIconAlignment(Control control)
    {
        return ErrorIconAlignment.MiddleLeft;
    }

    public new void SetIconAlignment(Control control, ErrorIconAlignment value)
    {
        base.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
    }

    #endregion
}

/ new ErrorProvider() new MyErrorProvider().

, , , , SetIconAlignment form.designer.cs...

+1

Source: https://habr.com/ru/post/1746159/


All Articles