Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 09:58

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Quick question

Discussion on Quick question within the .NET Languages forum part of the Coders Den category.

Closed Thread
 
Old   #1
 
hunterman01's Avatar
 
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?
hunterman01 is offline  
Old 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
SteveRambo is offline  
Old 12/18/2013, 23:45   #3
 
hunterman01's Avatar
 
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
Quote:
Originally Posted by SteveRambo View Post
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.
hunterman01 is offline  
Old 12/18/2013, 23:49   #4
 
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 140
Quote:
Originally Posted by hunterman01 View Post
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?
SteveRambo is offline  
Old 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);
        }
Aceking is offline  
Thanks
1 User
Old 12/19/2013, 00:58   #6
 
hunterman01's Avatar
 
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
Quote:
Originally Posted by SteveRambo View Post
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 View Post
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.
hunterman01 is offline  
Old 12/19/2013, 00:59   #7
 
elite*gold: 0
Join Date: Sep 2013
Posts: 197
Received Thanks: 140
Quote:
Originally Posted by Aceking View Post
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.
SteveRambo is offline  
Old 12/19/2013, 01:04   #8
 
hunterman01's Avatar
 
elite*gold: 20
Join Date: Dec 2006
Posts: 945
Received Thanks: 175
Quote:
Originally Posted by SteveRambo View Post
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.
hunterman01 is offline  
Old 12/19/2013, 01:13   #9
 
Super Aids's Avatar
 
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
Wrong section anyways.
Super Aids is offline  
Old 12/19/2013, 03:24   #10
 
elite*gold: 0
Join Date: May 2011
Posts: 648
Received Thanks: 413
Quote:
Originally Posted by Super Aids View Post
Wrong section anyways.
The coding section on epvp is mostly german. Good luck getting an answer over there.
Y u k i is offline  
Old 12/19/2013, 03:36   #11
 
elite*gold: 0
Join Date: Mar 2010
Posts: 183
Received Thanks: 74
Quote:
Originally Posted by Super Aids View Post
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 (;
.Light is offline  
Old 12/19/2013, 03:59   #12
 
Spirited's Avatar
 
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.
Spirited is offline  
Closed Thread


Similar Threads 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.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.