Must be a better way to do this?!

  • Thread starter Thread starter emma middlebrook
  • Start date Start date
E

emma middlebrook

Hi

This is a terrible way to do the following ...

private void TextBox_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == (char)13)
{
...
}
}

Is there a more elegant way? I see the System.Windows.Forms.Keys has
an Enter value but e.KeyChar's a char :-)

Emma Middlebrook
(e-mail address removed)
 
Yes, you are right.
e.KeyChar == Keys.Enter

As I said in the original post, Keys.Enter isn't a char ...

Anyone else with another better way suggestion that works :-)?

Emma Middlebrook
(e-mail address removed)
 
Ben Morris said:
The KeyDown event, which is sent just before each KeyPress event, contains
more information about the key pressed. In particular, its KeyCode and
KeyData properties return the Keys enumeration type. Try responding to this
event instead.

HTH

Ben M

Thanks Ben - I did notice this and was just wondering if there was
some kind of enumeration for when the return was specifically a char.
Thinking about it, I now realise this is a stupid thing to ask for as
a "char is a char". What I suppose I was after was an enumeration (so
providing nice symbol names for each char) whose values mapped to each
char. But imagine this for Unicode?!?? Am I right in this conclusion
that I was after something stupid?

Emma Middlebrook
(e-mail address removed)
 
Back
Top