0

I need to display text in a RichtTextBox with a green striped background. This means, the first line has a white background-color, the second has a green background-color, the third has white, the next green again etc.

How can I implement this?

The only way I imagine at the moment is setting the color for every textline. But I would have to fill each line with spaces to get whole lines. This way seems to be bad practice to me.

I think about something like OnPaint event, etc. where I can set the background color for every line before text is displayed.

If there is another TextControl that can handle my problem or I have to implement an own control this is an acceptable solution, too. Just give me some hint.

P.S.: I'm using .Net2.0.

Inno
  • 2,567
  • 5
  • 32
  • 44
  • An idea is to have the RTB transparent, and make your pattern behind, maybe using a custom panel on which the RTB is docked. – jv42 Oct 27 '11 at 08:02
  • It might not be the most practical depending on your requirements for lines (that's why I didn't post an answer). – jv42 Oct 27 '11 at 08:02

1 Answers1

1

One option to achieve this would be to use the open source http://scintillanet.codeplex.com/ project. Another SO user asked how to alternate row colors with this particular tool: Alternate row coloring in Scintilla

If you're not opposed to paying for it the WPF Actipro Syntax Editor supports this functionality though I'm not certain the WinForm version does.

A final option would be to use some code from #Develop or the WPF AvalonEdit

Community
  • 1
  • 1
robowahoo
  • 1,259
  • 9
  • 10