473,396 Members | 1,832 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,396 software developers and data experts.

Textbox Keydown

I have a bunch of code to get an input line from user like ensuring input is
a character rather than RightButton, and deleting past char if delete is
pressed. Can you think of an easier way to get the text that exist when the
user presses enter? Thanks.

private void m_textbox_KeyDown(object sender, KeyEventArgs e)
{
if (M_reading)
{
if (e.KeyCode == Keys.Enter)
{
M_reading = false;
mre.Set();
}
else
{
string key = e.KeyCode.ToString();
if (key.Length == 1 || e.KeyCode == Keys.Space) etc.
etc....
M_str += e.KeyCode.ToString();
}
}
}
Nov 16 '05 #1
1 3935
Hi denton,

I have a feeling you are trying to reinvent the wheel.

I assume you are using a textbox, so if your goal is to have the user
press a character key, you can use the KeyPress event to check if
Char.IsLetter(e.KeyChar), if so, you got a character key, if not, you can
set e.Handled to true to prevent any number of special symbols to ever
reach the TextBox.

It is not clear to me what you are trying to do with this code so if you
can explain it (pseudocode) I might be able to help you.

On Wed, 15 Dec 2004 14:47:04 -0800, denton <de*******@yahoo.com> wrote:
I have a bunch of code to get an input line from user like ensuring
input is
a character rather than RightButton, and deleting past char if delete is
pressed. Can you think of an easier way to get the text that exist when
the
user presses enter? Thanks.

private void m_textbox_KeyDown(object sender, KeyEventArgs e)
{
if (M_reading)
{
if (e.KeyCode == Keys.Enter)
{
M_reading = false;
mre.Set();
}
else
{
string key = e.KeyCode.ToString();
if (key.Length == 1 || e.KeyCode == Keys.Space) etc.
etc....
M_str += e.KeyCode.ToString();
}
}
}


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2

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

Similar topics

2
by: M O J O | last post by:
Hi, I have a TextBox on my form. I capture the KeyDown event and examines the e.KeyValue - that is, I examine it like this: dim chr = chr(KeyValue). This seams to work ok .... well almost....
2
by: Nick | last post by:
In VS 2003 and VS 2005 beta 2 I am trying to write a simple program. It has a datagrid and a textbox along with a menubar. There is a command in the menu bar which is "Run Query" and has the...
7
by: Seash | last post by:
Hi friends , here is the sample code private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if(e.KeyChar == 13) //enter { txtbox2.Focus(); }
3
by: Colin McGuire | last post by:
Hi, can I ask what I should be doing below. For some reason the method KeyDown doesn't exist in MyBase. Thank you Colin Private Sub TextBox1_KeyDown(ByVal sender As Object, _ ByVal e As...
5
by: Chris Wertman | last post by:
This seems like a simple one, ive searched the msdn and groups and cant come up with the answer however. I dont build gui apps very often (actually this is my first in oh 3 years) I have a...
6
by: Avi G | last post by:
Hi, what is the code to limit a textbox that will accept only text and not number private void button1_Click(object sender, EventArgs e) { if (textBox1.Text = "numbers") { // do something }
3
by: Rich | last post by:
Hello, I need to add a shift-F2 function to textboxes to bring up a dialogform with the expanded text contained in the respective Textbox. On any of the keydown events of a textbox I can only...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
2
by: jd | last post by:
I have several textboxes in which the end user can enter values. When the user presses the Enter key when in any of the textboxes, or leaves that textbox, I want a routine to run (mathematical...
1
by: jagwinderwalia | last post by:
Hi all i have build a autocomplete textbox control that works on keyup event in javascript. everytime a keyup is called , a request is send back to server and the suggestion are displayed in div...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.