我有一個表格,從此我想打開另一個表格,顯示在父表格的中間。爲此我使用此代碼:在另一個表格的中間生成小表格
using (var form = new Login())
{
var result = form.ShowDialog(this);
if (result == DialogResult.OK)
{
MessageBox.Show(form.getClientID);
}
}
在登錄表單中,我將StartPosition設置爲CenterParent。如果我像這樣稱呼它可行,但我認爲問題是這裏的「這個」:var result = form.ShowDialog(this);
但我不知道我應該如何告訴它從哪裏來的孩子形式。 我在登錄表格的代碼如下所示:
public string getClientID { get; set; }
public Login()
{
InitializeComponent();
}
private void loginButton_Click(object sender, EventArgs e)
{
this.getClientID = this.clientID.Text;
this.DialogResult = DialogResult.OK;
this.Close();
}
任何幫助,不勝感激!
編輯: 這是錯誤我得到var result = form.ShowDialog(this)
:
An Exception error of type "System.ArgumentException" has occurred in System.Windows.Forms.dll. Additional Information: A circular control reference has been issued. A control can not own itself or be superordinate.
不清楚。它是否有效?如果有效,那麼問題是什麼? – Steve
@Steve它工作爲止,我按一下按鈕,然後我收到此錯誤信息:System.ArgumentException‘發生在System.Windows.Forms.dll中「類型的異常錯誤’ 其它的信息:一個圓形的控制具有參考「(從德語翻譯成英文)這個錯誤彈出:」var result = form.ShowDialog(this);「 –