Jump to content
  • Advertisement
Sign in to follow this  
JasonHise

[.net] (C#) TextBox Selection Changed Notification

This topic is 5135 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I need to be notified right before the text in my text box changes so that I can see what the highlighted selection was before the change took place. However, I see no event to handle this. It would work equally well if I could find an event to notify me whenever the selected text changed, but this also seems not to exist. What can I use?

Share this post


Link to post
Share on other sites
Advertisement
You cannot catch this event server-side.
You can use the client-side javascript onchange event. However this is triggered after the textbox has lost its focus (someone clicked somewhere else in the document).
If you want detect changes immediately, you'll have to use a combination of onmousedown, onkeydown etc. events, or set a timer that checks for changes every now and then.

Share this post


Link to post
Share on other sites
I found another way to do it... when the text gets changed, I store the info about the current state, call undo on the edit box, get the info about the previous state, call undo again and restore the original info.

Share this post


Link to post
Share on other sites
You could try the following:

- get a PropertyDescriptor for the SelectedText Property
- attach an EventHandler with PropertyDescriptor.AddValueChanged

that EventHandler is called whenever the Property changes...

Share this post


Link to post
Share on other sites
that looks promising... although I don't entirely understand what I am supposed to pass in for the first parameter. Do I pass in the object that is handling the event? That wouldn't seem to make sense because I'm already passing it as part of the second argument.

Share this post


Link to post
Share on other sites
The first parameter should be the Control that exposes the property you're interested in, the TextBox in your case.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!