Can't clear textbox

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2009
Posts: 39
Reputation: jonnytabpni is an unknown quantity at this point 
Solved Threads: 0
jonnytabpni jonnytabpni is offline Offline
Light Poster

Can't clear textbox

 
0
  #1
May 3rd, 2009
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
Last edited by jonnytabpni; May 3rd, 2009 at 7:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: Can't clear textbox

 
0
  #2
May 3rd, 2009
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
Last edited by JerryShaw; May 3rd, 2009 at 7:20 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 39
Reputation: jonnytabpni is an unknown quantity at this point 
Solved Threads: 0
jonnytabpni jonnytabpni is offline Offline
Light Poster

Re: Can't clear textbox

 
0
  #3
May 4th, 2009
Thanks! worked brill!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC