Click here to Skip to main content
15,890,897 members
Home / Discussions / C#
   

C#

 
GeneralRe: lack the application for the process Pin
Jassim Rahma23-Mar-10 4:00
Jassim Rahma23-Mar-10 4:00 
GeneralRe: lack the application for the process Pin
Not Active23-Mar-10 4:17
mentorNot Active23-Mar-10 4:17 
Questioncall private void btnSave_Click(object sender, EventArgs e) Pin
Jassim Rahma22-Mar-10 11:58
Jassim Rahma22-Mar-10 11:58 
AnswerRe: call private void btnSave_Click(object sender, EventArgs e) Pin
Kristian Sixhøj22-Mar-10 12:02
Kristian Sixhøj22-Mar-10 12:02 
AnswerRe: call private void btnSave_Click(object sender, EventArgs e) Pin
ricmil4222-Mar-10 12:04
ricmil4222-Mar-10 12:04 
AnswerRe: call private void btnSave_Click(object sender, EventArgs e) Pin
Luc Pattyn22-Mar-10 14:47
sitebuilderLuc Pattyn22-Mar-10 14:47 
GeneralRe: call private void btnSave_Click(object sender, EventArgs e) Pin
ricmil4223-Mar-10 3:26
ricmil4223-Mar-10 3:26 
AnswerRe: call private void btnSave_Click(object sender, EventArgs e) [modified] Pin
DaveyM6922-Mar-10 12:35
professionalDaveyM6922-Mar-10 12:35 
As KeyEventArgs derives from EventArgs you can pass an instance of it to the click handler if you like so you can do:
C#
if (e.KeyCode == Keys.Enter)
    btnSave_Click(sender, e);
This will just run the code in the click handler. If you actually want to simulate a click then you should call PerformClick();
C#
if (e.KeyCode == Keys.Enter)
    btnSave.PerformClick();
The effect may be the same but it is possible that other things can happen in the control's internal code before the handler so base your decision on whether this could potentialy cause an issue (this could happen in a later version of the control and possibly break your application).

If the code that is being run due to the the Enter key press and button click is not directly related to the click then you should move it out to a separate method, and call your new method in each handler.
C#
private void txtName_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
        DoMyStuff();
}

private void btnSave_Click(object sender, EventArgs e)
{
    DoMyStuff();
}

private void DoMyStuff()
{
    //
}

Dave

Binging is like googling, it just feels dirtier. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Monday, March 22, 2010 6:42 PM

AnswerRe: call private void btnSave_Click(object sender, EventArgs e) Pin
AspDotNetDev22-Mar-10 13:37
protectorAspDotNetDev22-Mar-10 13:37 
GeneralRe: call private void btnSave_Click(object sender, EventArgs e) Pin
Not Active22-Mar-10 14:09
mentorNot Active22-Mar-10 14:09 
QuestionForm is Flickering Pin
Jassim Rahma22-Mar-10 11:53
Jassim Rahma22-Mar-10 11:53 
AnswerRe: Form is Flickering Pin
Kristian Sixhøj22-Mar-10 12:00
Kristian Sixhøj22-Mar-10 12:00 
QuestionThe WebBrowser control Pin
BuggingMe22-Mar-10 10:24
BuggingMe22-Mar-10 10:24 
Questionrecording sound from speakers Pin
rosin722-Mar-10 9:14
rosin722-Mar-10 9:14 
AnswerRe: recording sound from speakers Pin
DaveyM6922-Mar-10 10:33
professionalDaveyM6922-Mar-10 10:33 
QuestionModify Collection using LINQ Pin
uusheikh22-Mar-10 9:05
uusheikh22-Mar-10 9:05 
AnswerRe: Modify Collection using LINQ Pin
Gideon Engelberth22-Mar-10 9:30
Gideon Engelberth22-Mar-10 9:30 
AnswerRe: Modify Collection using LINQ Pin
Dave Kreskowiak22-Mar-10 10:50
mveDave Kreskowiak22-Mar-10 10:50 
GeneralRe: Modify Collection using LINQ Pin
uusheikh22-Mar-10 16:03
uusheikh22-Mar-10 16:03 
QuestionHow can I receive mail? Pin
Member 621528422-Mar-10 9:02
Member 621528422-Mar-10 9:02 
AnswerRe: How can I receive mail? Pin
Richard MacCutchan22-Mar-10 9:39
mveRichard MacCutchan22-Mar-10 9:39 
AnswerRe: How can I receive mail? Pin
DaveyM6922-Mar-10 10:29
professionalDaveyM6922-Mar-10 10:29 
QuestionRandom Number Question Pin
rmeister2922-Mar-10 7:50
rmeister2922-Mar-10 7:50 
AnswerRe: Random Number Question Pin
harold aptroot22-Mar-10 7:59
harold aptroot22-Mar-10 7:59 
AnswerRe: Random Number Question Pin
Migounette22-Mar-10 8:32
Migounette22-Mar-10 8:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.