我有一个对话框,其中包含文本框/等标签上的许多 Alt-Letter 快捷方式。该对话框可以以可编辑或只读模式显示数据。我收到了一项请求,要求在对话框处于只读模式时隐藏快捷方式的下划线。除了在运行时编辑标签文本(呃)之外,还有什么方法可以删除它们吗?
如果您不知道我所说的 alt-Letter 快捷方式指的是什么,请参阅 this问题。
最佳答案
您只需迭代控件并删除&符号即可。例如:
public partial class dlgSample : Form {
public dlgSample(bool isReadOnly) {
InitializeComponent();
if (isReadOnly) ZapMnemonics(this.Controls);
}
private void ZapMnemonics(Control.ControlCollection ctls) {
foreach (Control ctl in ctls) {
if (ctl is Label || ctl is Button) ctl.Text = ctl.Text.Replace("&", "");
ZapMnemonics(ctl.Controls);
}
}
}
关于c# - 有没有办法在运行时从控件中删除 Alt 字符快捷方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2472932/