In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to achieve C#button shortcut keys, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
Here are three ways to implement C # button shortcuts, such as Alt + *, Ctrl+* and other key combinations.
One of the C # button shortcuts: Alt + (button shortcut)
Add the & key name after the name when you set the Text property for button, label, menuStrip and other controls, such as button1.text= "OK (& O)". There will be a shortcut key, and press Alt+O to execute the button click event.
The second kind of C # button shortcut keys: Ctrl+* and other key combinations
Set the KeyPreview (register keyboard events with the form) property of the form to True in WinForm for which you want to use the key combination
Then use the KeyDown event of the form (which occurs when a key is pressed).
Example code of C # button shortcut key:
Private void * * _ KeyDown (object sender, KeyEventArgs e) {if (e.KeyCode = = Keys.F & & e.Control) {button1.PerformClick (); / / perform the action of clicking button1}}
Note for C # button shortcut keys:
1. * * represents the name of the form. You can take a look at the enumeration parameters of "Keys" to realize your needs.
2. Another problem is that when using the Ctrl + * shortcut key, the * key value may be entered at the same time when the focus is on a writable control, such as TextBox, so you need to add another sentence to set Handled to true to cancel the KeyPress event.
That is:
Private void * * _ KeyDown (object sender, KeyEventArgs e) {if (e.KeyCode = = Keys.F & & e.Control) {e.Handled = true; / / set Handled to true to indicate that the KeyPress event button1.PerformClick () has been processed
The third method of C # button shortcut key
Take button as an example. Add a contextMenuStrip1 to form and bind it to button, assuming button1. Add an item to contextMenuStrip1, then set a shortcut for it (the shortcut you want to add to button), and set its Visible property to false. In this way, the C# button shortcut key is set successfully.
The above is how to implement C#button keyboard shortcuts. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.