A
A.M-SG
Hi,
What would be the best way to assign the key F4 to a button?
Thank you,
Alan
What would be the best way to assign the key F4 to a button?
Thank you,
Alan
What would be the best way to assign the key F4 to a button?
"Gary Chang[MSFT]" said: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.
======================================================