奇妙なToolStripButton
ダブルクリックの問題が見つかりました。次の手順で問題を再現します。
- Windows フォーム アプリケーションを作成します。
ToolStrip
メイン フォームに a を追加します。- に を追加
ToolStripButton
しToolStrip
ます。 OpenFileDialog
メイン フォームにを追加します。ToolStripButton
プロパティ ツールボックスでのClick
イベントをダブルクリックします。toolStripButton1_Click
これをメソッドに追加します:openFileDialog1.ShowDialog();
- デバッグを開始します。
- をすばやくダブルクリックします
ToolStripButton
。
ここで問題が発生します。まず、ファイルを開くダイアログが表示され、それを閉じると、別のダイアログが表示されます。これは起こるべきではありません。もう一度閉じると、メインフォームに再描画の問題が発生する可能性があります。最後に、メイン フォームを閉じますが、プログラムはまだ実行されています。
自分で試してみて、それらすべてが発生した場合はお知らせください。
なぜそれらが起こるのですか?それを解決するにはどうすればよいですか?
これを使用して問題を再現できます。
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace WinForm
{
class MyForm : Form
{
private IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
openFileDialog1 = new OpenFileDialog();
toolStrip1 = new ToolStrip();
toolStripButton1 = new ToolStripButton();
toolStrip1.SuspendLayout();
this.SuspendLayout();
toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripButton1 });
toolStripButton1.Text = "toolStripButton1";
toolStripButton1.Click += new EventHandler(toolStripButton1_Click);
this.Controls.Add(toolStrip1);
toolStrip1.ResumeLayout(false);
toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
private OpenFileDialog openFileDialog1;
private ToolStrip toolStrip1;
private ToolStripButton toolStripButton1;
public MyForm()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MyForm());
}
}
}