[英]How to create a striped richtextbox?
I need to display text in a RichtTextBox with a green striped background. 我需要在带有绿色条纹背景的RichtTextBox中显示文本。 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. 我考虑过类似OnPaint事件之类的事情,在这里我可以在显示文本之前为每行设置背景色。
If there is another TextControl that can handle my problem or I have to implement an own control this is an acceptable solution, too. 如果还有另一个TextControl可以解决我的问题,或者我必须实现自己的控件,这也是可以接受的解决方案。 Just give me some hint. 给我一些提示。
PS: I'm using .Net2.0. PS:我正在使用.Net2.0。
One option to achieve this would be to use the open source http://scintillanet.codeplex.com/ project. 实现此目的的一种方法是使用开放源代码http://scintillanet.codeplex.com/项目。 Another SO user asked how to alternate row colors with this particular tool: Alternate row coloring in Scintilla 另一个SO用户询问如何使用此特定工具替换行颜色 : 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. 如果您不愿意为此付费,则WPF Actipro语法编辑器支持此功能,尽管我不确定WinForm版本是否支持。
A final option would be to use some code from #Develop or the WPF AvalonEdit 最后的选择是使用#Develop或WPF AvalonEdit中的一些代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.