A
から継承するクラスがありUserControl
ます:
public class A : UserControl
{
private Form1 _form; // class Form1 : Form { //... }
private A()
{
InitializeComponent();
}
public A(Form1 form) : this()
{
_form = form;
}
}
そして、ビジュアル コード デザイナーがコードを作成します。
private void InitializeComponent()
{
this.a = new A((Form1)this); // here I myself added foo object in ctor
//...
}
private A a;
そして、私はエラーを持っています:
Warning 1 Type 'A' does not have a constructor with parameters of types Form. 0 0
私は何を間違えましたか?そして、これを回避する方法は?
編集
Form1
問題は、ctor で親 (私の場合) への参照を知る必要があることです。ctor が完了するまでプロパティが設定されない.Parent
ため、プロパティを使用できません。そのため、この複雑な方法で親を渡すことを選択しました。.Parent
で。
問題はまだ解決していません