Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Leaders
Posted
So, unless I'm missing something, you can use the KeyPress and KeyDown event to check when a key is pressed.

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...