473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

getting key pressed

Hello,

I have put a simple form together with a lable and a textbox. I want to be
able to trap the ENTER key when is pressed. So I can check the texted
enetered. If correct, call up the main program, if not re-prompt for the
user ID.

Thanks,

Jerry
Jan 15 '07 #1
3 2475
Added code:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace passGL

{

public partial class UserLogin : Form

{

public UserLogin()

{

InitializeComponent();

}

private void label1_Click(object sender, EventArgs e)

{

}

private void UserLogin_Load(object sender, EventArgs e)

{

}

private void txtBxUserID_TextChanged(object sender, EventArgs e)

{

// if (e.KeyChar == Keys.M) e.Handled = true;

// if (e.Equals( Keys.M ) )

// {

// Console.WriteLine("Enter pressed!!");

// }

}

}

}

"Jerry" <jp******@general-steel.comwrote in message
news:12*************@corp.supernews.com...
Hello,

I have put a simple form together with a lable and a textbox. I want to
be able to trap the ENTER key when is pressed. So I can check the texted
enetered. If correct, call up the main program, if not re-prompt for the
user ID.

Thanks,

Jerry

Jan 15 '07 #2
Hi,
Have a look at this post (the answer at the bottom in particular!).
Obviously this person is doing something different, but you will need
to trap the 'Enter' button in a similar way.

http://forums.microsoft.com/MSDN/Sho...78440&SiteID=1

HTH,
James Randle.

Jerry wrote:
Added code:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace passGL

{

public partial class UserLogin : Form

{

public UserLogin()

{

InitializeComponent();

}

private void label1_Click(object sender, EventArgs e)

{

}

private void UserLogin_Load(object sender, EventArgs e)

{

}

private void txtBxUserID_TextChanged(object sender, EventArgs e)

{

// if (e.KeyChar == Keys.M) e.Handled = true;

// if (e.Equals( Keys.M ) )

// {

// Console.WriteLine("Enter pressed!!");

// }

}

}

}

"Jerry" <jp******@general-steel.comwrote in message
news:12*************@corp.supernews.com...
Hello,

I have put a simple form together with a lable and a textbox. I want to
be able to trap the ENTER key when is pressed. So I can check the texted
enetered. If correct, call up the main program, if not re-prompt for the
user ID.

Thanks,

Jerry
Jan 15 '07 #3
Hi Jerry,

I wonder if you are trying to mimick the functionality of an
AcceptButton. Form.AcceptButton will fire the defined button event on an
Enter key anywhere on the Form, likewise the Form.CancelButton will trap
Escape. In the button event find out if the text entry is valid.

If you really want to capture the Enter key inside the TextBox, try using
the KeyPress event

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
MessageBox.Show("Enter");
}

or the KeyDown or KeyUp event

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
MessageBox.Show("Enter");
}

--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Harlin Seritt | last post by:
I have the following script. Two widgets call the same function. How can I tell inside of the called function which button called it?: def say_hello(): print 'hello!' print widget root =...
3
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
7
by: Tyron | last post by:
I need to know if the Left Button of the Mouse is clicked in the WM_NCMOUSEMOVE Notification but this Message doesnt contain the Mouse Button States as WM_MOUSEMOVE does. So how can I get them? ...
2
by: Cederstrom | last post by:
Hello Group, I have created an ASP.NET page. The page consist of the following items: - Button A - Button B - UserControl When I press Button A, I execute the following code: ViewState =...
2
by: mwatcher | last post by:
Hi all, I am using .net 2.0. How can I get the current state of the mouse button (e.g.. Mouse Button Right is pressed). I'm not in a mouse event handler routine. What I wanna do is to check if...
5
by: =?Utf-8?B?dWxpbGxpbGxpYQ==?= | last post by:
I've had two issues plaguing me for 4 months now and I haven't gotten anywhere. I'm into making 2D games and these things are essential to games. These are my issues: 1. I need timing precise...
3
by: Jeff | last post by:
I have had this function work perfectly in IE and am trying to get it to work in Firefox. I have seen plenty of questions and answers on the web for how to get and check the key pressed but nothing...
9
by: phopman | last post by:
Hello! I am currently working on a project. And have been assigned to get up to speed quickly on php. And even though I love the language, it's not easy to get up to speed in like 2 seconds :-) ...
8
by: jodleren | last post by:
Hi It is late and I am tired. I cannot remember how to check which of my buttons on the form was pressed. There are all submit's. Like echo "P=".$_POST; // and eventually using isset() ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.