如何在C#上设置按钮的快捷键? [英] How to set a shortcut key for a button on C# ?
本文介绍了如何在C#上设置按钮的快捷键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按Enter键时,我尝试使用此代码按下Login按钮。但它没有用。
有什么问题?
I have tried this code to get pressed Login Button when I press Enter. But its not working.
what is the problem??
private void Logout_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
LoginButton.PerformClick();
}
}
我的尝试:
What I have tried:
private void Logout_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
LoginButton.PerformClick();
}
}
推荐答案
不要这样做。
相反,请查看表单的属性窗格,然后找到AcceptButton属性。将其设置为LoginButton,系统将为您处理。
Don't do it that way.
Instead, look at the Properties pane for your form, and locate the "AcceptButton" property. Set that to "LoginButton" and the system will handle it all for you.
这篇关于如何在C#上设置按钮的快捷键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文