?
Solved

&Next as button name makes the button work even when only 'N' is pressed.

Posted on 2006-03-23
18
Medium Priority
?
259 Views
Last Modified: 2010-04-16
I have an application where on a form theres a button with text on it as "&Next" meaning when we press alt+N then the button should function as if its clicked.
But If I press only 'N' then it should not do anything, which is not the case with my application. If I press 'N' only then also its responding as if its clicked( There is no function which is trapping the key movements and doing some manipulations.) I want to make sure that this does not happen. How to solve it?
0
Comment
Question by:manjeetbothra
  • 6
  • 6
  • 5
  • +1
18 Comments
 

Author Comment

by:manjeetbothra
ID: 16268261
The application is in C#
0
 
LVL 10

Accepted Solution

by:
dkloeck earned 180 total points
ID: 16268394
use the key down event like this:

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
  if ((e.Alt) && (e.N))
  {
      //Here goes your button funktion
      OnButton1Pressed();
  }
}
0
 
LVL 8

Expert Comment

by:vinhnl
ID: 16268402
You have to capture event Keypress of the form (and all control if it can focus), check if it's key 'N' and do somethings.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 8

Expert Comment

by:vinhnl
ID: 16268448
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
  if (e.KeyData == Keys.A)
  {
      OnButtonNextPressed();
  }
}
0
 
LVL 8

Expert Comment

by:vinhnl
ID: 16268453
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
  if (e.KeyData == Keys.N)
  {
      OnButtonNextPressed();
  }
}
0
 

Author Comment

by:manjeetbothra
ID: 16268474
The problem is that even if I write the KeyDown(pressed/ or whatever) function, the
"button click" event is being generated which works as if button is being clicked and hence calls the NEXT() function. Helppp
0
 
LVL 28

Expert Comment

by:strickdd
ID: 16268476
Have you tried setting the focus or Tab order to some other control? Sometimes if certain controls or parent controls have the focus then pressing the special key will activate that control.
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16268500
can you show us your KeyPressed event funktion?

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs
e)
{
  if ((e.Alt) && (e.KeyData == Keys.N))
  {
      //Here goes your button funktion
      OnButton1Pressed();
  }
}

You have to write e.KeyData == Keys.N instead of e.N in my last post :)  I didn't check it
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16268509
and vinhnl you forgot the alt key :P
0
 

Author Comment

by:manjeetbothra
ID: 16268559
Yes pressing 'N' on the parent form also behaves as clicking the button.
Also the problem does not happen if the button text does not have "&". But if we dont have "&" then alt + N wont show and underline under the N when I press alt(ya ya i can make the text underlined by the function) but I dont want that.
0
 
LVL 8

Assisted Solution

by:vinhnl
vinhnl earned 195 total points
ID: 16268560
Ah Manjeetbothra,

I think that it's standard of bottom control of windows. If you focus on some buttom (&OK, &Cancel, &Next, &Pre,..) and click a lettre (not need alt), windows understand defaut that you chois this buttom
0
 

Author Comment

by:manjeetbothra
ID: 16268617
vinhnl ,
Can you give some KB article/ Link where this is said.
0
 
LVL 8

Expert Comment

by:vinhnl
ID: 16268634
You can test this knowledge. You show a messagebox with YESNO question. If you press 'Y' or 'N', the dialog will close.
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16268671
thats true, if you use mnemonic it will be clicked if u press the letter after the &, u don't need to hit the alt key
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16268786
U can set of mnemonic and just make it with keyDown, if u want to have your N underlined  just add a OnPaint event to your button and use a funktion like e.graphics.drawLine() to paint the line under the text
0
 

Author Comment

by:manjeetbothra
ID: 16269093
Thanks for a quick and efficient job guys
0
 
LVL 8

Expert Comment

by:vinhnl
ID: 16269115
de rien !
0
 

Author Comment

by:manjeetbothra
ID: 16269251
What does this(de rien) means and which language is it?(vietnamese?)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question