samiullah478 Posted December 21, 2006 Posted December 21, 2006 Aslam alikum plz tell me abt that how to assign a short key to a button in vb.net like CTRL+S Quote
mskeel Posted December 21, 2006 Posted December 21, 2006 (edited) In the text of the button put an & in front of the letter you want to use for the hot key. superButton.Text = "&Save" 'You’d probably set this through the designer Will look like Save and hit with hot keys using Alt+S. Edited December 21, 2006 by mskeel Quote
*Experts* Nerseus Posted December 21, 2006 *Experts* Posted December 21, 2006 Ctrl-S is a bit harder. I believe there are really only two options: 1. If you have a menu, you can set the menu item's Shortcut property to CtrlS. 2. If you don't have a menu, you'll have to trap this yourself. Generally, you'll set the form's KeyPreview property to True - this lets the form get all keyboard events before any controls. Then, in the KeyDown event, check to see what the user was pressing. Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.Control And e.KeyCode = Keys.S Then MessageBox.Show("wow") End If End Sub If you want this code to click a button (not recommended), you can use Button1.PerformClick(). If your code is behind a button, it's best to move it into a function (use Refactor->Extract Method, it's fun!). Then you would call that function from your button and in the KeyDown event. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Leaders snarfblam Posted December 21, 2006 Leaders Posted December 21, 2006 If you want a quick and dirty hack, you can use a MenuStrip, create a ToolStripMenuItem for each shortcut key, attach a handler, and then set the MenuStrip's visible property to false. Like I said, it is a quick and dirty hack. I would never use it, but its there. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.