【发布时间】:2017-10-30 09:41:54
【问题描述】:
我和this guy有或多或少相同的问题,但他的帖子已经有2年了,所以我想我可以开一个新的。
在程序中我使用标签,我发现mnemonics on labels trigger the enter event of the next control in the tab order。所以实现了click 和enter 方法。但问题就在这里。我创建了一个测试程序。该程序持久化了两个标签,一个按钮和一个文本框。
第二个标签只是用来控制enter 事件是否被触发。当我点击ALT 时,下划线看起来很好,但是当我按下第二个键(Reset)时没有任何反应。此外,如果出现下划线并且我再次按下ALT 键,他不会消失并且button 完全忽略ALT 是否被按下。
我用 VisualStudio 2013 搬到了另一台电脑,但得到了相同的结果。我下载了 VisualStudio 2017,尝试创建新程序 => 也不起作用。
英语不是我最熟悉的语言,所以如果你能在我写错时给我提示,我很高兴。 我希望有人可以帮助我。
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void reset_Click(object sender, EventArgs e)
{
textBox.Text = "";
}
private void button_Click(object sender, EventArgs e)
{
textBox.Text = "Button";
}
private void nothing_Enter(object sender, EventArgs e)
{
textBox.Text = "nothing";
}
}
}
Form1.Designer.cs
this.reset.Click += new System.EventHandler(this.reset_Click);
this.button.Click += new System.EventHandler(this.button_Click);
this.nothing.Enter += new System.EventHandler(this.nothing_Enter);
【问题讨论】:
-
文字太多了。请尽量缩短您的帖子,仅提供核心信息以了解和重建您的问题。
-
好的,我会这样做的。
-
现在好点了吗?
-
是的,现在好多了。
-
标签被设计为充当“伙伴”控制的助记符。由 Label.ProcessMnemonic() 实现。 Primary 有助于为 TextBox 提供焦点。这个标签没有好友。考虑覆盖 ProcessCmdKey() 以识别击键。
标签: c# .net winforms visual-studio mnemonics