私のアプリはWinForms.NET4(C#)で、ボタンを押した後、フォームの1つが自動的に閉じ続けます。
- フォームにはデフォルトの[承認]ボタンと[キャンセル]ボタンがありますが、これらには触れていません。
- ButtonTestConnection_Clickイベントがあります。このイベントは、クリックされるとその役割を果たしますが、何らかの方法でフォームを閉じます。
- 私はマウスを使用してボタンをクリックしているので、これはカスケードキーストロークの場合ではありません。
- この関数でDialogResultを設定していません。
また、これを迷わないようにチェックしようとしました。閉じる/ this。通話を破棄しましたが、見つかりませんでした。
コードは次のとおりです。
private void ButtonTestConnection_Click (object sender, System.EventArgs e)
{
this.Enabled = false;
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
this.ProgressBar.Minimum = 0;
this.ProgressBar.Maximum = 500;
this.ProgressBar.Value = 0;
this.ProgressBar.Visible = true;
this.ButtonTestConnection.Visible = false;
try
{
while (this.ProgressBar.Value < this.ProgressBar.Maximum)
{
// Some proxy code.
this.ProgressBar.Value++;
}
}
catch
{
}
this.ProgressBar.Visible = false;
this.ButtonTestConnection.Visible = true;
this.ProgressBar.Invalidate();
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(10);
this.Cursor = System.Windows.Forms.Cursors.Default;
this.Enabled = true;
System.Windows.Forms.MessageBox.Show(result.ToString());
}