Yal*_*lda 8 .net c# visual-studio winforms
我需要在Windows应用程序中有Button一个UserControl(不Form)响应"Enter"命中,一个按钮被设置为Accept Button一个Form工作的方式.
我不能让按钮聚焦,因为我需要其他控件来集中更改标签.
任何帮助真的很感激:)
Jay*_*cee 12
AcceptButton是Form的一个属性,不能用于UserControl.您可以简单地覆盖ProcessCmdKey,只要用户控件具有焦点,这将起作用.否则,如果您有多个可能处于活动状态的控件,则需要单独使用表单的AcceptButton或覆盖表单中的ProcessCmdKey.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
button.PerformClick();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4107 次 |
| 最近记录: |