Windows フォーム内の同意ボタンに問題があります。フォームには 2 つのボタン (OK とキャンセル) があります。フォーム内で、cancel と accept - Button のプロパティを特定のボタンに設定します。それに加えて、両方のボタンの単純なクリック イベントも作成しました。しかし、アプリケーションを実行して Enter キーを押すと、Click-Method 内のブレークポイントがヒットせず、何も起こりません。一方、キャンセルボタンは問題なく機能します。受け入れボタンとキャンセルボタンを切り替えても、受け入れボタンは機能せず、アプリケーションは入力を無視するようです。デザイナーを何度か調べましたが、この動作につながる可能性のあるものは見つかりませんでした。ボタンをクリックすると、クリックイベント自体も正常に機能します。これは、入力に関するものです。だから私の質問は:
Designer:
//
// SearchForm
//
this.AcceptButton = this.BtnSearch;
this.CancelButton = this.BtnCancel;
//
//BtnSearch
//
this.BtnSearch.DialogResult = System.Windows.Forms.DialogResult.OK;
this.BtnSearch.Location = new System.Drawing.Point(12, 60);
this.BtnSearch.Name = "BtnSearch";
this.BtnSearch.Size = new System.Drawing.Size(75, 23);
this.BtnSearch.TabIndex = 1;
this.BtnSearch.Text = "Search";
this.BtnSearch.Click += new System.EventHandler(this.BtnSearch_Click);
//
// BtnCancel
//
this.BtnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.BtnCancel.Location = new System.Drawing.Point(108, 60);
this.BtnCancel.Name = "BtnCancel";
this.BtnCancel.Size = new System.Drawing.Size(75, 23);
this.BtnCancel.TabIndex = 5;
this.BtnCancel.Text = "Cancel";
this.BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
Form:
private void BtnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void BtnSearch_Click(object sender, EventArgs e)
{
//DoStuff
}