954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't clear textbox

Hi Folks,

I have a textbox which looks out for keypresses when it is in focus.
For example, when the ";" key is pressed, a few functions are called. THe problem is, is that in the KeyPress function for the textbox, i have textbox1.Text = ""; to clear it however it doesn't work.

It's as if the text box executes the KeyPress function (hence my clear statement) prior to actually outputting the ";" in the box.

So in the end, ";" gets displayed (However if I keep pressing ";", I only ever see one)

Any ideas on how I can fix this? Thanks

jonnytabpni
Light Poster
39 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Simple... Just set e.Handled to true
When e.Handled is set to true, then the keypress event stops there, otherwise it is passed up the chain to the TextBox.
// Jerry

JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

Thanks! worked brill!

jonnytabpni
Light Poster
39 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You