|
Hello sir/s, im pj.. how can i assign a shortcut key on a certain button, instead of putting an Ampersand ("&") besides the text of the button.. For exampe.. instead of pressing ALT + (the access key) for a button.. i would like only a single key.. like "ENTER" key to be associated with a certain button.. please Give me a sample code or any directions.. Thank you so much..
|
|
|
|
|
Trap the key you are interested in and invoke the event handler for the button or menu item
|
|
|
|
|
Sir, Thank you so much for replying on my message. Can you give me a sample code? I'm really having a hard time figuring out the event handlers, because i tried putting up some codes on the "KeyPress" event, but i only ended up having more errors. Thank you again sir.
|
|
|
|
|
What errors are you getting? You can check it like this:
<br />
private void Form1_KeyPress(object sender, KeyPressEventArgs e)<br />
{<br />
if (e.KeyChar == (char)Keys.A)<br />
{<br />
}<br />
<br />
if (e.KeyChar == (char)Keys.B)<br />
{<br />
}<br />
}<br />
|
|
|
|
|
Yes sir.. but i did it this way.. i was trying to designate the Keypress Event of a Button.. For example.. [Logout] Button..
if ( (e.KeyChar).ToString() == Keys.Escape)
{
if (MessageBox.Show("Do you wish to exit?", "Exit", MessageBoxButtons.YesNo) == DialogResult.No)
return;
this.Close();
}
But its not working..
|
|
|
|
|
1. If you want to quit your application when escape button is pressed then set form's cancelbutton property will help you.
2. You can test it like this:
<br />
if (e.KeyChar == (char)Keys.Escape)<br />
MessageBox.Show("escape was pressed");<br />
It works in the same way for Enter key too
|
|
|
|
|
Thank you so much sir.. I was trying to associate the "ENTER" and "/" key for the Event of a Button's Click.. But i could not make it work.. this is the error..
"Error 1 Operator '==' cannot be applied to operands of type 'char' and 'System.Windows.Forms.Keys' ".. I believe that the "Enter" Key is a windows forms key.. how can i CAST it to be something else..
|
|
|
|
|
Did you cast it to char as I showed in the example?
|
|
|
|
|
Thank you so much for that sir.. It works.. Sir, how can i can assign a hotkey to a Button?.. Ahm, for example.. I want a Button_Click event to be associated with a shortcut key.. Instead of me Pressing the Button itself, i just have to press a key from the keyboard.. like; Pressing the F2 key to be associated with
the Event of a Click of a Button.. Im really sorry for this sir.. I ask a lot of questions. I'm just new to C#, and I'm only a student.
|
|
|
|
|
if (e.KeyChar == (char)Keys.F2)
Button_Click(null,EventArgs.Empty)
|
|
|
|
|
Sir, i appreciate it so much.. Thank you very much for all the help that you have lend me.. Thank you so much sir..
|
|
|
|
|
You are welcome
|
|
|
|
|
Sir, thank you so much for all the help that you lend me.. .. until next time sir..
|
|
|
|
|
Hi,
for printable characters (letters, digits, punctuation) you should use the KeyPress event;
its event arg provides a KeyChar property which is a char, so don't compare it to
(char)Keys.A instead compare it to 'a' or 'A'.
special characters (escape, enter, ...) don't fire the KeyPress event; you should use
the KeyDown (possibly KeyUp) event for these; its event arg provides a KeyCode property
which is a Keys, so that one you can compare to Keys.Escape and others.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
For the specific cases of Enter and Escape there's an easier solution. The AcceptButton and CancelButton properties of the form can be given an event handler as a value (the buttons click handler).
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
disable hotkeys ctrl, alt,del,win through c# and then enable code
tahir
|
|
|
|
|
I've already replied to your first post which is the same as this one. It is rude to ask the same question twice. I have given a direction to explore, if you are lazy no one will do the work for you
|
|
|
|
|
The veteran poster had also tried to start up this elite discussion thread in a rated PG non-programming forum (aka) Lounge.
|
|
|
|
|
Don't Cross Post and repost.
SSK.
|
|
|
|
|
I have a project developed in 2.0 Framework, can i use a Forum which is developed in 1.1 Framework.
Please suggest is there any problem to integrate the forum.
Thanks in advance
Arun Kr.
Arun Kr
|
|
|
|
|
Kumar Arun wrote: I have a project developed in 2.0 Framework, can i use a Forum which is developed in 1.1 Framework.
Can you use source code from a .NET 1.1 project? Sure. Most of the .NET 2.0 BCL is backwards compatible, but there are breaking changes.
Can you use a .NET 1.1 compiled assembly in your .NET 2.0 project?? Most likely not, but only if the .NET 1.1 assembly MUST use the .NET 1.1 CLR. If this is the case, then no, you can't use the assembly because you cannot load two different versions of the .NET CLR into the same process.
If the .NET 1.1 assembly will work fine running under the .NET 2.0 CLR, then yes, you can use it.
But, like I said, there ARE breaking changes between .NET 1.1 and .NET 2.0 and above.
|
|
|
|
|
i want to get start menu programs in a listbox of my application
tahir
|
|
|
|
|
You can iterate over the files and folders in these folders to extract the information you need:
C:\Documents and Settings\All Users\Start Menu\Programs
and
C:\Documents and Settings\%username%\Start Menu\Programs
|
|
|
|
|
In WinForm Project.
I want to touch off keyboard's event and capture "Ctrl+Enter" in a Form.
How to do?
|
|
|
|
|
You can handle the Keypress event and check for the modifiers and keys that are pressed
|
|
|
|