Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,I encountered such a question. How to add border to the selected text in the richtextbox when a button is clicked. And the border disappeared when clicked again. Could you give me some suggestions?
Thanks.
Posted
Updated 21-Jun-10 0:00am
v2

1 solution

So you're saying that you want to draw a line around the selected text when a button is clicked...is that right?

If so, it's not all that difficult, but you have to understand the RichTextBox somewhat well.

The RichTextBox has a function called GetPositionFromCharIndex which will AFAIK give you the top, left coordinate of the position. So with the positions of the first character in the selection, the character right after the selection, and the largest font width of that selection, you should be able to determine the bounds of the box.

Then, just use the RichTextBox.CreateGraphics and draw the box. To clear it, just invalidate the RichTextBox.
 
Share this answer
 
Comments
shujsj2010 24-Jun-10 22:33pm    
Hello William Winner,
Thanks for your suggestion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900