473,507 Members | 12,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Functions

I have a windows project that there is Form, and inside the form there are
three buttons (Button1, Button2, Button3). The text of the buttons are 'F2',
'F3' and 'F4'. When the user press F2 function, the button1 will be clicked.
When press F3 function the button2 will be clicked...and so on. I want to
associate the F1, F2 and F3 key press with the click of the buttons. Does
anyone know how to do it?
Nov 15 '05 #1
3 1722
Not sure what you are trying to do but to capture a click event you use
this

this.button1.Click += new System.EventHandler(this.button1_Click);

Or if you mean when a user hits one of the Function keys (F1-F12) you can
capture it with this

this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.MyProgra m_KeyDown);

and in MyProgram_KeyDown you do

private void MyProgram_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case Keys.F1:
doButton1();
break;
case Keys.F2:
doButton2();
...
}
}

private void button1_Click(object sender, System.EventArgs e)
{
doButton1();
}

private void doButton1()
{
// do stuff that happens when the users clicks button 1 or hits F1
}
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #2


If what you want is that your button luck like pressed when the user press the (F1-F3) key, then you just simply to send a button onClick event and it'll be captured for the button event manager.

I hope this help.
Nov 15 '05 #3
I have other controls on the form (DBgrid, TextBox,....). If the focus is on
one of this controls the "this.KeyDown" event is not fired when I press the
F2 key. I want the key function works even if the focus is on another
control on the form.
"Morten Wennevik" <Mo************@hotmail.com> escreveu na mensagem
news:opryvtmk06hntkfz@localhost...
Not sure what you are trying to do but to capture a click event you use
this

this.button1.Click += new System.EventHandler(this.button1_Click);

Or if you mean when a user hits one of the Function keys (F1-F12) you can
capture it with this

this.KeyDown += new
System.Windows.Forms.KeyEventHandler(this.MyProgra m_KeyDown);

and in MyProgram_KeyDown you do

private void MyProgram_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
switch(e.KeyCode)
{
case Keys.F1:
doButton1();
break;
case Keys.F2:
doButton2();
....
}
}

private void button1_Click(object sender, System.EventArgs e)
{
doButton1();
}

private void doButton1()
{
// do stuff that happens when the users clicks button 1 or hits F1
}
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3326
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
5818
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
21
746
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
17
3589
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
2
3759
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
5877
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
3961
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
14
4166
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
7
3946
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
6
9593
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.