Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Assign F4 to a button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
A.M-SG - 02 Feb 2006 01:02 GMT
Hi,

What would be the best way to assign the key F4 to a button?

Thank you,

Alan
"Gary Chang[MSFT]" - 02 Feb 2006 10:27 GMT
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.
======================================================
Stoitcho Goutsev (100) - 02 Feb 2006 14:57 GMT
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.

Signature

HTH
Stoitcho Goutsev (100)

> Hi Alan,
>
[quoted text clipped - 43 lines]
> rights.
> ======================================================

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.