473,382 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 BindingNavigator (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
NorthwindDataSet, not my real dataset, as this is a replication of the
issue due to NDA problems):

private void productsBindingNavigatorSaveItem_Click(object
sender, EventArgs e)

{

this.Validate();

this.productsBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.northwindD ataSet);

}

Regards,

Adrian Pavone

Applications & Technical Engineer

CVW Group


Nov 20 '07 #1
9 2373
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.com
"Wingot" <wi****@newsgroup.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 BindingNavigator (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 NorthwindDataSet, not my real dataset, as this is a replication of the issue due to NDA problems):



private void productsBindingNavigatorSaveItem_Click(object sender, EventArgs e)

{

this.Validate();

this.productsBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.northwindD ataSet);



}



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.caspershouse.com]
Posted At: Tuesday, 20 November 2007 11:19 AM
Posted To: microsoft.public.dotnet.languages.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.com

"Wingot" <wi****@newsgroup.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 BindingNavigator (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
NorthwindDataSet, not my real dataset, as this is a replication of the
issue due to NDA problems):

private void productsBindingNavigatorSaveItem_Click(object
sender, EventArgs e)

{

this.Validate();

this.productsBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.northwindD ataSet);

}

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
BindingNavigator 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(object 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.microsoft.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
BindingNavigator 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(object 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/managednewsgroups/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***@online.microsoft.com]
Posted At: Tuesday, 20 November 2007 3:39 PM
Posted To: microsoft.public.dotnet.languages.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
BindingNavigator 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(object 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***@online.microsoft.com]
Posted At: Wednesday, 21 November 2007 11:55 AM
Posted To: microsoft.public.dotnet.languages.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 KeyPressEventArgs.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
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...
1
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. ...
10
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...
4
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...
11
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...
5
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: ...
1
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> ...
6
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.