Stoitcho
Thu Feb 02 08:58:49 CST 2006
Alan,
In adition to what Gary said, I want to add that if you don't want to use
PInvoke in your program and I assume you do have a main menu a possible
workaround (suggested in the books) is to create a hidden (visible = false)
menu item and asign F4 short cut to it. Then you can use the same event
handler as for the button's click.
--
HTH
Stoitcho Goutsev (100)
""Gary Chang[MSFT]"" <v-garych@online.microsoft.com> wrote in message
news:adVqWN%23JGHA.3680@TK2MSFTNGXA02.phx.gbl...
> Hi Alan,
>
>>What would be the best way to assign the key F4 to a button?
>
> The general convention to add a shortcut key of a winform is to use Win32
> API RegisterHotkey, then override your form's WndProc function to trap the
> WM_HOTKEY message, and call the target button's PerformClick() method.
> Please refer to the following article for the sample of using
> RegisterHotkey:
>
> Simple steps to enable Hotkey and ShortcutInput user control
>
http://www.codeproject.com/cs/miscctrl/ashsimplehotkeys.asp
>
> Note: To assign F4 to the form's button1 control, the sample code in step3
> and step4 of the above sample would be as the following ones:
> 3.
> protected override void WndProc(ref Message m)
> {
> if (m.Msg == 0x0312)
> button1.PerformClick();
> base.WndProc(ref m);
> }
>
> 4.
> FrmStartup.RegisterHotKey(this.Handle,
> this.GetType().GetHashCode(), 0, 0x73); //VK_F4 (73)
>
>
> Wish it works!
>
> Best regards,
>
> Gary Chang
> Microsoft Community Support
> ======================================================
> PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
> AM PST, February 14, 2006. Please complete a re-registration process by
> entering the secure code mmpng2006 when prompted. Once you have entered
> the
> secure code mmpng2006, you will be able to update your profile and access
> the partner newsgroups.
> ======================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from this issue.
> ======================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> ======================================================
>