0

I am use Graphics.DrawString for writing text on image bellow is my code

 graphicsImage.DrawString(message, new Font("arial", 15, FontStyle.Regular), new SolidBrush(StringColor), drawRect);

I am wrap the text content by using rectangle f. now i want change color specific word. how can i do that ?

jai pundir
  • 1
  • 1
  • 6
  • 3
    You must draw it separately. – Lasse V. Karlsen Aug 10 '17 at 08:21
  • "hey welcome how are you" that is my sentence which i draw. so how can change welcome color. is this not possible – jai pundir Aug 10 '17 at 08:23
  • 1
    You must draw `hey` in one color, `welcome` in another and then `how are you` probably in the same color as `hey`. Unfortunately you cannot do this with 1 call to DrawString which means you need to take on the word wrapping logic yourself. – Lasse V. Karlsen Aug 10 '17 at 08:25
  • you have any idea for this – jai pundir Aug 10 '17 at 08:31
  • 1
    No, doing proper word wrapping is a complex topic and not up my alley. All I can tell you is that you won't be able to do it with one call to DrawString, nor do I think there is any good alternative in the .NET framework. – Lasse V. Karlsen Aug 10 '17 at 08:32
  • how about using a `RichTextBox`. Then you could look at [this helpful answer](https://stackoverflow.com/a/21980957/5174469) or [this one](https://stackoverflow.com/a/1926822/5174469) – Mong Zhu Aug 10 '17 at 08:54
  • i am not use ritchtextbox – jai pundir Aug 10 '17 at 08:59
  • @jaipundir I understand that. That was a suggesttion. Because it would make the parsing of the string and drawing certain words in certain colours much easier – Mong Zhu Aug 10 '17 at 09:11
  • What are you targetting: Winforms, WPF, ASP..? __Always__ tag your question correctly! - Other than that: Yes, it is work, tedious work. Btw, while not easier you should use TextTenderer for better quality.. – TaW Aug 10 '17 at 09:30
  • console application c# – jai pundir Aug 10 '17 at 09:47

0 Answers0