473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function Keys Saving

Hey,

I am using Visual Studio 2008 Beta 2 for some application development in
C#, but I presume that the following question applies equally well to
any environment.

I have created some data entry forms for customer details, transactions,
etc. What I would like to do is make it so that the buttons across the
top right of the BindingNavigato r (New, Delete, Save, respectively) were
mapped to the function keys F2-F4. I have tried searching on the web for
how to use function keys in C# (or Visual C#), but couldn't find much
that made any sense.

Another flow on from this problem is that when I take a look at the
source code, the method that saves the details is expecting various
arguments from the click event I believe, but if I call this method from
a function key or another button on the form, these arguments would not
be available. What would be the best way to call the saving method
(which has not been changed from the default) from within another
method. I would prefer not to replicate the code within the function so
as to avoid redundancy and potential later errors. The code for the save
method looks like this (bear in mind that this case uses the
NorthwindDataSe t, not my real dataset, as this is a replication of the
issue due to NDA problems):

private void productsBinding NavigatorSaveIt em_Click(object
sender, EventArgs e)

{

this.Validate() ;

this.productsBi ndingSource.End Edit();

this.tableAdapt erManager.Updat eAll(this.north windDataSet);

}

Regards,

Adrian Pavone

Applications & Technical Engineer

CVW Group


Nov 20 '07 #1
9 2393
Adrian,

Regarding the mapping, you should be able to handle the KeyUp event and look for the appropriate value in the Keys enumeration (which will be passed to you in the KeyEventArgs instance passed to you (through the KeyCode, KeyValue, or KeyData property).

As for calling the click event handler, the sender and e arguments are not used by your code, so I would separate them to another method which does not take any parameters and then call that method from the click event handler, as well as your other event handlers.

If you need some sort of parameters passed to the method, then you expose only what you need.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Wingot" <wi****@newsgro up.nospamwrote in message news:00******** *************** *****@CVW.local ...
Hey,



I am using Visual Studio 2008 Beta 2 for some application development in C#, but I presume that the following question applies equally well to any environment.



I have created some data entry forms for customer details, transactions, etc. What I would like to do is make it so that the buttons across the top right of the BindingNavigato r (New, Delete, Save, respectively) were mapped to the function keys F2-F4. I have tried searching on the web for how to use function keys in C# (or Visual C#), but couldn’t find much that made any sense.



Another flow on from this problem is that when I take a look at the source code, the method that saves the details is expecting various arguments from the click event I believe, but if I call this method from a function key or another button on the form, these arguments would not be available. What would be the best way to call the saving method (which has not been changed from the default) from within another method. I would prefer not to replicate the code within the function so as to avoid redundancy and potential later errors. The code for the save method looks like this (bear in mind that this case uses the NorthwindDataSe t, not my real dataset, as this is a replication of the issue due to NDA problems):



private void productsBinding NavigatorSaveIt em_Click(object sender, EventArgs e)

{

this.Validate() ;

this.productsBi ndingSource.End Edit();

this.tableAdapt erManager.Updat eAll(this.north windDataSet);



}



Regards,



Adrian Pavone

Applications & Technical Engineer

CVW Group



Nov 20 '07 #2
Thanks for the point about moving the functionality to a separate
method, I remember doing that in my basic C# training, and just forgot
it now.

Any chance that you could point me to a resource (or tutorial) on how to
use KeyUp events (and presumably KeyDown and KeyPress as well)? I
presume it is just a matter of setting up an EventHandler for keyboard
input or similar?

From: Nicholas Paldino [.NET/C# MVP]
[mailto:mv*@spam .guard.caspersh ouse.com]
Posted At: Tuesday, 20 November 2007 11:19 AM
Posted To: microsoft.publi c.dotnet.langua ges.csharp
Conversation: Function Keys Saving
Subject: Re: Function Keys Saving

Adrian,

Regarding the mapping, you should be able to handle the KeyUp event
and look for the appropriate value in the Keys enumeration (which will
be passed to you in the KeyEventArgs instance passed to you (through the
KeyCode, KeyValue, or KeyData property).

As for calling the click event handler, the sender and e arguments
are not used by your code, so I would separate them to another method
which does not take any parameters and then call that method from the
click event handler, as well as your other event handlers.

If you need some sort of parameters passed to the method, then you
expose only what you need.


--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Wingot" <wi****@newsgro up.nospamwrote in message
news:00******** *************** *****@CVW.local ...

Hey,

I am using Visual Studio 2008 Beta 2 for some application development in
C#, but I presume that the following question applies equally well to
any environment.

I have created some data entry forms for customer details, transactions,
etc. What I would like to do is make it so that the buttons across the
top right of the BindingNavigato r (New, Delete, Save, respectively) were
mapped to the function keys F2-F4. I have tried searching on the web for
how to use function keys in C# (or Visual C#), but couldn't find much
that made any sense.

Another flow on from this problem is that when I take a look at the
source code, the method that saves the details is expecting various
arguments from the click event I believe, but if I call this method from
a function key or another button on the form, these arguments would not
be available. What would be the best way to call the saving method
(which has not been changed from the default) from within another
method. I would prefer not to replicate the code within the function so
as to avoid redundancy and potential later errors. The code for the save
method looks like this (bear in mind that this case uses the
NorthwindDataSe t, not my real dataset, as this is a replication of the
issue due to NDA problems):

private void productsBinding NavigatorSaveIt em_Click(object
sender, EventArgs e)

{

this.Validate() ;

this.productsBi ndingSource.End Edit();

this.tableAdapt erManager.Updat eAll(this.north windDataSet);

}

Regards,

Adrian Pavone

Applications & Technical Engineer

CVW Group


Nov 20 '07 #3
Hi Wingot,

Thanks for your feedback.

There is one problem regarding KeyDown/KeyUp events. Because if the
keyboard focus is in TextBox, the F2 key press will not be sent to the
BindingNavigato r control. So if there are many controls on the form, your
keyboard focus may possible in any of these controls, which means we have
to handle KeyDown/KeyUp events for all controls, which is not a good
practice.

To resolve this problem, you may set Form.KeyPreview property to true and
then only handle Form.KeyDown/KeyUp event. This property will help the
parent form to monitor all the keyboard events in it. Then, you may handle
the event something like this:

private void Form1_KeyDown(o bject sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
MessageBox.Show ("F2");
}
}

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '07 #4
On Nov 19, 11:39 pm, je...@online.mi crosoft.com ("Jeffrey Tan[MSFT]")
wrote:
Hi Wingot,

Thanks for your feedback.

There is one problem regarding KeyDown/KeyUp events. Because if the
keyboard focus is in TextBox, the F2 key press will not be sent to the
BindingNavigato r control. So if there are many controls on the form, your
keyboard focus may possible in any of these controls, which means we have
to handle KeyDown/KeyUp events for all controls, which is not a good
practice.

To resolve this problem, you may set Form.KeyPreview property to true and
then only handle Form.KeyDown/KeyUp event. This property will help the
parent form to monitor all the keyboard events in it. Then, you may handle
the event something like this:

private void Form1_KeyDown(o bject sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
MessageBox.Show ("F2");
}

}

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer tohttp://msdn.microsoft. com/subscriptions/managednewsgrou ps/default.asp...
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) athttp://msdn.microsoft. com/subscriptions/support/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
That is very good to know. Woo hoo!
Nov 20 '07 #5
Hey Jeffrey,

Thanks, I was trying to figure out how to do this very thing last night.
I could get it to work if I made the textboxes have the KeyUp event, but
not for just the form.

And yes, I agree that this sort of setting should not be applied to all
the controls on the form, which is why I spent about an hour trying to
figure out how to do it. If only I'd seen your email before leaving work
:)

Thanks,
Wingot

-----Original Message-----
From: "Jeffrey Tan[MSFT]" [mailto:je***@on line.microsoft. com]
Posted At: Tuesday, 20 November 2007 3:39 PM
Posted To: microsoft.publi c.dotnet.langua ges.csharp
Conversation: Function Keys Saving
Subject: Re: Function Keys Saving

Hi Wingot,

Thanks for your feedback.

There is one problem regarding KeyDown/KeyUp events. Because if the
keyboard focus is in TextBox, the F2 key press will not be sent to the
BindingNavigato r control. So if there are many controls on the form,
your
keyboard focus may possible in any of these controls, which means we
have
to handle KeyDown/KeyUp events for all controls, which is not a good
practice.

To resolve this problem, you may set Form.KeyPreview property to true
and
then only handle Form.KeyDown/KeyUp event. This property will help the
parent form to monitor all the keyboard events in it. Then, you may
handle
the event something like this:

private void Form1_KeyDown(o bject sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F2)
{
MessageBox.Show ("F2");
}
}

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...default.aspx#n
otif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '07 #6
Hi Wingot,

Thanks for your feedback.

I hope you have got it working by using Form.KeyPreview property. If you
still need any help, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '07 #7
Nope, It's working, thanks Chris.

I gave it a try last night when I got home, and had a bit of a play with
it to make it so I could actually use the New and Delete buttons as
well.

Form.KeyPreview worked like a charm.

As a matter of interest, from the name "KeyPreview ", that would imply to
me that it checks it, but then passes it through to the control if it
doesn't find a valid action. Would that be correct?

Regards,
Wingot
-----Original Message-----
From: "Jeffrey Tan[MSFT]" [mailto:je***@on line.microsoft. com]
Posted At: Wednesday, 21 November 2007 11:55 AM
Posted To: microsoft.publi c.dotnet.langua ges.csharp
Conversation: Function Keys Saving
Subject: Re: Function Keys Saving

Hi Wingot,

Thanks for your feedback.

I hope you have got it working by using Form.KeyPreview property. If
you
still need any help, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti.../default.aspx#
notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.
Nov 22 '07 #8
Hi Wingot,

Thank you for the confirmation!

Yes, your understanding is correct. After the form's event handlers have
completed processing the keystroke, the keystroke is then assigned to the
control with focus.

If you only wanted to handle the keystrokes at the Form level without
passing to the focused controls, you may set the KeyPressEventAr gs.Handled
property in your form's KeyPress event handler to true. The official MSDN
link below contains the details for this property:
http://msdn2.microsoft.com/en-us/lib...form.keyprevie
w.aspx

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Nov 22 '07 #9
Hi Wingot,

Have you reviewed my last reply to you? Does it answer your further
question? If you still have anything unclear, please feel free to tell me,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support

Nov 27 '07 #10

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

Similar topics

1
5417
by: Don W. | last post by:
I need to use some function keys as speed-keys (instead of clicking a button with the mouse.) Using this code doesn't display any codes for the function keys: <html><body> <SCRIPT LANGUAGE="JavaScript"> document.onkeypress = Check_key; function Check_key() {
1
6840
by: Steve | last post by:
I would like to override the IsInputKey function in order to trap the arrow up/down keys in the Key Events. I understand that arrow keys don't have a char representation and thus, hard to trap. Someone wrote this override for IsInputKey in C# which apparently worked, and I tried to convert it to VB.Net but not working. Here is the C# version and following - my conversion. It would be great if anyone out there knows how to do this...
10
7554
by: danibe | last post by:
I never had any problems storing pointers in STL containers such std::vector and std::map. The benefit of storing pointers instead of the objects themselves is mainly saving memory resources and performance (STL containers hold *copies* of what's passed to them via the insert() method). However, I am not sure how to accomplish that using std::set. For various reasons, I cannot use vector or map in my application. But I would like to...
4
6695
by: Broeisi | last post by:
Hello, I'm trying to write a console based program in C in Linux. I want to use the function keys in my program, but I don;t know how to let the C program know when for exmaple the F1 key is pressed. I want to be able to use all 12 Function keys in my program. Can someone help me maybe on this one? I guess that those function keys also have an ascii number.
11
6632
by: Yelena Varshal via AccessMonster.com | last post by:
Hello, I have a problem with one of msaccess.exe API calls that work on my desctop but does not work on the laptop from within MS ACCESS. There is a lot of differences between 2 computers including one running Office 2000 and another running Office 2003. This code was created by a previous developer. I need to find the description and parameters of the API calls. I found the article ...
5
4147
by: Luke Skywalker | last post by:
Hi to all, I need to suppress the function keys (F1, F2, F3 ecc.) to use these keys to do other operations within the web pages of my application. I wrote this code: document.onkeydown=function(evt) { if (evt==undefined) evt="";
1
2049
by: Sam Samson | last post by:
Greeetings All .. For my users convenience I have mapped function keys F2 .. F12 to change the tabs on the Tabcontrol. Works like a charm <ominous musicuntil one hits F8</ominous music> That particular tabpage has a webbrowser object embedded in it .. and after it flicks to that tabpage it no longer plays nice with the other Tabpages .. click on another Tab using the mouse and all is wonderful again. (unless
6
3036
by: Paul Bilokon | last post by:
Hi, Is there a more elegant and/or efficient way of saving the keys from a hash_map in a vector? Perhaps using assign or other algorithms? The problem, of course, is that we are dealing with an iterator of pairs... hash_map<string, void *> hashMap; // ... vector<string> keys; keys.reserve(hashMap.size());
0
8675
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8897
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6521
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4370
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.