|
You last visited: Today at 09:58
Advertisement
Quick question
Discussion on Quick question within the .NET Languages forum part of the Coders Den category.
12/18/2013, 23:06
|
#1
|
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
|
Quick question
Hey what's up everyone,
I'm stuck on something so simple it blows my mind.
Okay, what im trying to do is when you press enter on a form it does something
For instance
Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
// do something
}
}
I know several ways of going about this but like i said very simple just caught up for some reason.
Any ideas?
|
|
|
12/18/2013, 23:40
|
#2
|
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 140
|
I don't see a question anywhere
|
|
|
12/18/2013, 23:45
|
#3
|
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
|
Quote:
Originally Posted by SteveRambo
I don't see a question anywhere
|
For a second, i thought you were just some noob who had no idea what i was talking about. Then i looked at your profile, so i will make it a little bit clearer.
That little bit of code actually does nothing what so ever. Whenever you press enter, nothing happens. Which is strange.
|
|
|
12/18/2013, 23:49
|
#4
|
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 140
|
Quote:
Originally Posted by hunterman01
For a second, i thought you were just some noob who had no idea what i was talking about. Then i looked at your profile, so i will make it a little bit clearer.
That little bit of code actually does nothing what so ever. Whenever you press enter, nothing happens. Which is strange.
|
What do you want it to do? I mean, there's obviously no code inside the if statement ... Or am I misreading something?
|
|
|
12/19/2013, 00:29
|
#5
|
elite*gold: 0
Join Date: Feb 2006
Posts: 726
Received Thanks: 271
|
The enter button is considered a special input key, for example many buttons will use enter as a way to trigger the button click, and as such the form excludes enter from being caught in a key event.
Use:
Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
// Enter pressed
//doSomething();
button1.Text = "lllll";
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
|
|
|
12/19/2013, 00:58
|
#6
|
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
|
Quote:
Originally Posted by SteveRambo
What do you want it to do? I mean, there's obviously no code inside the if statement ... Or am I misreading something?
|
Let me elaborate a little bit more, Basically when someone press's enter it will launch another application for example
Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
System.Diagnostics.Process.Start("test.exe");
}
}
Quote:
Originally Posted by Aceking
The enter button is considered a special input key, for example many buttons will use enter as a way to trigger the button click, and as such the form excludes enter from being caught in a key event.
Use:
Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
// Enter pressed
//doSomething();
button1.Text = "lllll";
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
|
*EDIT*
That worked, thanks bro.
|
|
|
12/19/2013, 00:59
|
#7
|
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 140
|
Quote:
Originally Posted by Aceking
The enter button is considered a special input key, for example many buttons will use enter as a way to trigger the button click, and as such the form excludes enter from being caught in a key event.
Use:
Code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
// Enter pressed
//doSomething();
button1.Text = "lllll";
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
|
What? No. The reason that pressing the Enter key doesn't trigger the form's KeyDown/KeyUp/KeyPressed events is most likely because some other control is taking the focus away from the form and whenever a key is pressed, the event it sent to that control instead of the form itself. In that case, you just need to handle the specific control's events instead of the form's.
|
|
|
12/19/2013, 01:04
|
#8
|
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
|
Quote:
Originally Posted by SteveRambo
What? No. The reason that pressing the Enter key doesn't trigger the form's KeyDown/KeyUp/KeyPressed events is most likely because some other control is taking the focus away from the form and whenever a key is pressed, the event it sent to that control instead of the form itself. In that case, you just need to handle the specific control's events instead of the form's.
|
You and him were both right, i had something else going on.
|
|
|
12/19/2013, 01:13
|
#9
|
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
|
Wrong section anyways.
|
|
|
12/19/2013, 03:24
|
#10
|
elite*gold: 0
Join Date: May 2011
Posts: 648
Received Thanks: 413
|
Quote:
Originally Posted by Super Aids
Wrong section anyways.
|
The coding section on epvp is mostly german. Good luck getting an answer over there.
|
|
|
12/19/2013, 03:36
|
#11
|
elite*gold: 0
Join Date: Mar 2010
Posts: 183
Received Thanks: 74
|
Quote:
Originally Posted by Super Aids
Wrong section anyways.
|
Agreeing with Yuki. Also this question out of context doesn't have anything to do with a CO Private Server BUT in context it does (;
|
|
|
12/19/2013, 03:59
|
#12
|
elite*gold: 12
Join Date: Jul 2011
Posts: 8,205
Received Thanks: 4,107
|
Alright. If that's the case, I'll look out for English posts in that section. The moderator of that section is also English speaking, I believe. But yes, this is completely unrelated to Conquer Online, so I will be moving this with a 24 hour redirect. Also, since the thread has been successfully resolved, I suppose it can be closed. Cheers.
|
|
|
Similar Threads
|
Quick Question
01/07/2012 - EO PServer Hosting - 1 Replies
Hello, good evening.
I have a question, how do I create items 8 +255 F-Soul and all elements +255:confused::confused:
|
QuiCK QuESTion
05/11/2011 - Eudemons Online - 3 Replies
Does "~Sword~Stalker~. belongs to this section ? Cause im really curious . Reply fast .
|
Very quick question need quick answer!
10/26/2009 - Dekaron - 5 Replies
On line 21 of the CE non agro, what is the regular speed of the mobs? what do I change??
I wanna non agro that doesnt make the monsters so speedy... thansk!
|
A quick question.
04/26/2009 - SRO Private Server - 3 Replies
Do any of u guys get like lag when u try to attack a mob or like it wont attack as fast? or when u sell something it takes a while for it to leave ur inventory? Does anyone else have this problem?
|
All times are GMT +1. The time now is 09:58.
|
|