我有一個應用程序,我在窗體上添加了一個usercontrol。 當我在用戶控件構造檢查this.parentForm
它給出了一個空引用如何parentForm引用爲空?
我的用戶的代碼是這樣
public UserControl1()
{
InitializeComponent();
if (this.ParentForm != null)//ParentReference is null
{
MessageBox.Show("Hi");//Does Not get Called
}
}
那麼我如何才能得到parnetForm的引用,以便我可以像ReSize那樣在userControl上處理一些父事件? – 2012-01-09 06:32:23
@Nilesh正如我所說,在ParentChanged事件中執行它。 – 2012-01-09 06:38:55