Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to draw text on the text of RichTextBox. For ex: i want to draw a word "hello" on the word
"hello" of RichTextBox whose text is "hello world!". How do i do it?
Posted

1 solution

Use one of the Graphics.DrawString[^] methods. This assumes you know how to position the string "hello" over the "hello" in "hello world". This is not trivial.
 
Share this answer
 
Comments
TheKingofdemon33 13-Mar-14 13:35pm    
but it doesn't exactly draw the string over it.
gggustafson 13-Mar-14 14:55pm    
That implies that you do not know one or more of the critical formatting parameters. If you are using

DrawString ( String, Font, Brush, Single, Single )

and are off by just one pixel, you will get a misaligned image. Likewise if the font is not exactly on, your result will also be misaligned.

If you have control over the RichTextBox generation process then you should have all the information you need. Also, then, you can select the text you want to redraw and perform the redrawing directly using RichTextBox methods.

Would you care to share the purpose of your efforts?

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