4

ソフトウェアの基本フォーム クラスが 1 つある派生フォーム クラスを使用します。

派生フォームでは、DataBinding を広範囲に使用して BusinessObjects を処理し、すべて IDataErrorInfo を実装し、ErrorProviders を使用して GUI への偽の入力でカスタム エラー メッセージをスローします。

base-form-class に関数を実装して Form 上のすべての ErrorProvider-Components を取得し、Form 上のすべての Control の IconAlignment を左に設定する方法を探しています (右は間隔の問題であるため)。

どんなヒントでも歓迎...

IconAlignment を設定するコード:

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

    foreach (Control subControl in control.Controls)
    {
        SetErrorProviderIcon(errorProvider, subControl);
    }
}
4

1 に答える 1

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()

正確に思い出すことはできませんがSetIconAlignmentform.designer.csファイルに渡された値を再シリアル化するには、フォームのデザイナーを開く必要がある場合があります...

于 2010-05-19T19:51:54.807 に答える