1

問題は、PropA = true のように、カスタム コントロール コンストラクターでプロパティのすべての初期値を既に初期化していることです。しかし、最終的なカスタム コントロールをフォームにドラッグ アンド ドロップすると、いくつかの値が別の値に変更されます (例: PropA = false)。

なぜそれが起こるのか理解できます。これは、非常に冗長な作業を行う自動生成コードによるものです。つまり、私たち (プログラマー) がプロパティ ウィンドウで変更したプロパティのみを、自動生成されたコードで designer.cs ファイルに追加する必要があります。冗長なコード (および、私の場合のように不要なコード) を designer.cs ファイルに追加する必要があるのはなぜですか。これは、デフォルト値をなくすコード実行順序のフローです。

public Form(){
   //I replace the InitializeComponent() method by its content right in here
   myCustomControl = new MyCustomControl(); <---- everything is already
   //set up OK at here, no need auto-generated code for my custom properties.

   SuspendLayout();

   /////Initialize properties
   //My custom properties go here, they are already set to default values in my
   //custom control constructor (the line right at the very top above).
   //And that means, all the auto-generated code below are preparing to erase
   //all those default values unexpectedly.

   myCustomControl.PropA = false; //While, PropA is already set to true 
   //in MyCustomControl() constructor and what I want is it should be true, not false
   //but the designer doesn't understand me or I have to understand it????

   //The same for other custom properties of mine
   ....
   ....
   ResumeLayout(false);
   PerformLayout();
}

デザイナーを理解する方法、またはデザイナーに私を理解させる方法を知りたいですか???

あなたの助けは非常に高く評価されます!

前もって感謝します!

4

0 に答える 0