我们使用派生的形式类别,并为我们的软件提供一个基本类别。

在派生的表单上,我们广泛使用数据指标来处理我们的业务对象,所有这些都实现了idataErrorinfo,并将错误输入在GUI上向GUI扔向GUI。

现在,我搜索一种在基本级别中实现函数的方法,以在表单上获取所有ErrorProvider-Components,并为左侧表单上的每个控件设置ICONALIGNMENT(因为右侧是间距 - 问题)。

任何提示欢迎...

设置IconAlignment的代码:

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

    foreach (Control subControl in control.Controls)
    {
        SetErrorProviderIcon(errorProvider, subControl);
    }
}
有帮助吗?

解决方案

我们使用了继承 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 文件...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top