私はこれから1つのフォームを開き、別のフォームを開き、親フォームの中央に表示します。そこで私はこのコードを使用しました:別のフォームの中央に小さいフォームを作成する
using (var form = new Login())
{
var result = form.ShowDialog(this);
if (result == DialogResult.OK)
{
MessageBox.Show(form.getClientID);
}
}
私はStartPositionをCenterParentに設定しました。私はそれがうまくいけばそれは動作しますが、問題はここの "this"です:var result = form.ShowDialog(this);
しかし、私はそれがどこからchildformになるべきかを伝えるべきか分かりません。 ログインフォームでの私のコードは次のようになります。
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();
}
すべてのヘルプは大歓迎です!
EDIT: これは私が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.Windows.Forms.dllで" System.ArgumentException "という型の例外エラーが発生しました 追加情報:コントロールが自分自身を所有することはできませんし、上級者でもありません。 "(ドイツ語から英語に翻訳されている)、このエラーはポップアップします。" var result = form.ShowDialog(this); " –