Keystroke Catch for custom Textbox Control

Needbass2004

Newcomer
Joined
Jul 14, 2004
Messages
1
Ok, I know it can be easily done. Want I want is to make a custom
Textbox control...Because I like making my apps customized.

I need to be able to capture the keystrokes once my control is clicked on.
I also need to know the values of Enter, Backspace, and Escape, so that
it edits like the normal textbox. I don't want it to capture all keystrokes globally, because that wouldn't be very professional if someone clicked my textbox then hit another window and typed.


I am using GDI+ to do the textbox in layers.
Bottom layer will be a background
2nd Layer will the text
3rd layer will be the 'GLASS' looking highlights that will look cool.

Thanks.
 
Additonally if you use the KeyDown or KeyUp event check to see what the key is, is simple by using the Keys enumerable.

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

KeyPress is useful to allow only letters or numbers for example.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(!Char.IsControl(e.KeyChar) && !Char.IsNumber(e.KeyChar))
{
e.Handled = true;
}
}

The code above will not allow anything that isn't a control (ENTER, ESCAPE, CTRL etc or a number)
 
Back
Top