Windows 窗体中的接受按钮有问题。表单包含两个按钮(确定和取消)。在表单中,我将取消和接受的属性 - 按钮设置为特定按钮。除此之外,我还为两个按钮创建了一个简单的 Click - 事件。但是,当我运行应用程序并按 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
}