richTextbox-高亮显示完整行 [英] richTextbox - Highlight complete line

查看:122
本文介绍了richTextbox-高亮显示完整行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在richTextbox中突出显示整行
注意:如果文本长度较小,则还应突出显示整行.
而且,如果没有任何文本,则可以突出显示richTextBox行.
如果可能的话,请给我解决方案.
非常感谢!

I want to highlight the complete line in richTextbox
Note : If the textlength is small then also complete line should be highlighted.
And without any text is it possible to highlight the richTextBox line.
Please give me the solution if its possible.
Thanks so much!

推荐答案

您的意思是选择吗?
基本上,您需要计算起始位置和长度(例如,通过查找行定界符来确定行的起始位置)和长度,并适当地分配属性SelectionStartSelectionLength.

还有一种通过文件中的索引找出行位置的方法.对于WPF,您需要使用类System.Windows.Documents.TextPointer,对于System.Windows.Forms.RichTextBox,请使用GetLineFromCharIndexGetPositionFromCharIndex.

仅当您尝试实现它时,我才能提供更多详细信息,如果您有任何问题,请询问后续问题.另外,您需要回答我的问题并解释输入的内容(哪行?插入符号所在的行,按索引行还是什么?).

说到没有文本的行的突出显示":答案是否定的:如果没有文本,就没有行".这不是文本控件(所有控件)的工作方式.请问为什么?


OP的新更新(图片)显示,请求的功能未选中,因此此答案不适用.
不过这不是我的错.
请参阅我的其他答案.

—SA
Do you mean selection?
Basically, you need to calculate starting position and length, (for example, of line by finding line delimiters) and assign the properties SelectionStart and SelectionLength appropriately.

There is also a way to find out line position by its index in the file. For WPF, you need to use the class System.Windows.Documents.TextPointer, for System.Windows.Forms.RichTextBox, use GetLineFromCharIndex and GetPositionFromCharIndex.

I can reach for further detail only if you try to implement it and ask a follow-up question if you have any problems. Also, you need to answer my questions and explain what you have on input (which line? line where the caret is, line by index or what?).

Speaking of the "highlight" of the line with no text: the answer is negative: there are no "lines" if there is no text. This is not how text controls (all of them) work. May I ask why, by the way?


New update from OP (picture) show that the requested feature is not selection, so this answer is not applicable.
This is not my fault though.
Please see my other Answer.

—SA


您的问题对我来说有点困惑,因为我想让您突出显示Richtextbox的行或者它是否已完全填充,如果是,那么我发现了此链接-[在richtextbox控件中突出显示当前行] [ ^ ].阅读该主题可能会对您有帮助.
your question is little bit confusing for me as I getting you want to highlight Line of richtextbox either its is complete filled or not if so then I found this link-[Highlight current row in richtextbox control][^]. read the thread it might help you.


回答后续问题提交图片后的问题:

您当然首先没有正确地解释它.您在图片上显示的内容(谢谢,您终于通过这篇文章回答了我的问题,但是您最好在问题中输入内容)...这是我在与Venkatesh的猜测中的最后猜测.可惜你这么晚回来了,所以我们所做的只是猜测.

当然可以,但是如果 far ,此演示文稿与现有的RTF功能确实相去甚远.我几乎100%确信您显示的用户界面不是基于富文本格式的.最好的办法是创建一个全新的编辑器代码.我不是在开玩笑,因为我知道其他团队做了什么(不是为了强调您,而是出于更严重的原因).如果您真的想咬一口子,请查看Sharp开发中的编辑器实现: http://en.wikipedia.org/wiki/SharpDevelop [ ^ ],http://sharpdevelop.com/ [ ^ ]-完整的源代码可用.

您仍然可以使用RichTextBox,这将非常困难.此组件是高度面向文本的.甚至在滚动区域中找到相对坐标也是困难的,因为所有测量都是在字符位置进行的,并且所有字符和行的大小都不同(尽管在WPF中可以解决此问题).因此,第一个大问题将只是找到水平条纹的坐标.宽度如何?您将必须找到文本行并计算其边界大小.渲染这个东西真是一场噩梦.您不能仅将控件放在RichTextBox的顶部,这会阻止鼠标/键盘与文本的交互. RichTextBox中的低级渲染?即使您执行此操作,它如何与下面的行中的所有更改交互?等等.我会更轻松地编写一个全新的编辑组件…

您是否真的想为此解决问题?我建议您将时间花在一些更有用的事情上.

—SA
Answering follow-up Question after the picture was submitted:

You certainly did not explain it properly in first place. What you show on the picture (thank you, you finally answered my questions by this post, but you better put in in your Question)... this is what was my last guess in our guesswork with Venkatesh. Too bad you came back that late, so all we did was guesswork.

Of course, it is possible, but this presentation if far, really far away from existing rich text functionality. I''m almost 100% much sure the UI you show is not based on rich text. Best thing to do would be to create a brand new editor code. I''m not joking, because I know what other teams did (not for the sake of you highlight but for more serious reasons). If you really would like to bite a bullet, please look at the editor implementation in Sharp develop: http://en.wikipedia.org/wiki/SharpDevelop[^], http://sharpdevelop.com/[^] — full source code is available.

You can still want to use RichTextBox, this would be <d>very difficult. This component is strongly text-oriented. Even finding a relative coordinate in the scrolled area is difficult, because all measurements are done in character positions, and all characters and lines are of different sizes (this problem is solvable in WPF though). So first big problem will be just to find coordinates of you horizontal strip. How about width? You will have to locate the text line and calculate its bounding size. And rendering of this thing is a real nightmare. You cannot just put a control on top of the RichTextBox would block your mouse/keyboard interaction with the text. Low-level rendering in RichTextBox? Even if you do this, how can it interact with all changes in the line underneath? And so on. I would more easily write a brand new edit component…

Do you really want to break your teeth on this problem? I would suggest you spend your time on something more useful.

—SA


这篇关于richTextbox-高亮显示完整行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆