Archived

This topic is now archived and is closed to further replies.

Keeping text selected in a RichTextBox

This topic is 5147 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've made a custom ruler component in C# that mimicks the functionality of WordPad's ruler. The only feature I haven't implemented yet is keeping focus in the rich edit when the ruler is clicked. After looking around for a while the only solution I found for catching the click events before they are processed is to use the AddMessageFilter method in Application. But the problem with that is it would then require the ruler to depend on the application as well as a rich edit. I would like to avoid that if possible. Does anybody know how I could have the ruler component not grab the focus when it's clicked? Preferably a way that only has to be implemented inside the ruler component? [edited by - Big Sassy on November 13, 2003 5:54:16 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i don''t know anything about C#, so i don''t know if this is possible or not, but if you have a OnSetFocus handler available (one that handles the WM_SETFOCUS window message,) or maybe it''s called GotFocus?, then just forward the focus setting on to the rich edit control via a SetFocus call of your own.

Share this post


Link to post
Share on other sites
Actually I just realized that I'm attacking this problem the wrong way. I probably should have said before that when something is selected in the RichTextBox it will become de-selected when it loses focus. Well, actually the RichTextBox will still have it's SelectionStart and SelectionLength properties set, but it wont display the text as being selected until you tab back into the RichTextBox, restoring focus.

What I should be asking is how can I keep the text visibly selected even when it loses focus inside a RichTextBox?

PS - Thanks for the tip, AP. It helped me move in the right direction.

[edited by - Big Sassy on November 13, 2003 4:29:28 PM]

Share this post


Link to post
Share on other sites