Textbox Keydown

G

Guest

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();
}
}
}
 
M

Morten Wennevik

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top