为所选文字添加边框 [英] Add border to selected text

查看:133
本文介绍了为所选文字添加边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我遇到了这样的问题.单击按钮时如何在RichTextBox中的选定文本上添加边框.当再次单击该边框时,该边框消失了.你能给我一些建议吗?
谢谢.

Hello everyone,I encountered such a question. How to add border to the selected text in the richtextbox when a button is clicked. And the border disappeared when clicked again. Could you give me some suggestions?
Thanks.

推荐答案

所以,您是说要在单击按钮时在所选文本周围画一条线...对吗? />
如果是这样,那并不是那么困难,但是您必须对RichTextBox有所了解.

RichTextBox具有一个名为GetPositionFromCharIndex的函数,该函数将通过AFAIK为您提供该位置的顶部,左侧坐标.因此,通过选择中第一个字符的位置,选择后的字符以及该选择的最大字体宽度,您应该能够确定框的边界.

然后,只需使用RichTextBox.CreateGraphics并绘制框即可.要清除它,只需使RichTextBox无效.
So you''re saying that you want to draw a line around the selected text when a button is clicked...is that right?

If so, it''s not all that difficult, but you have to understand the RichTextBox somewhat well.

The RichTextBox has a function called GetPositionFromCharIndex which will AFAIK give you the top, left coordinate of the position. So with the positions of the first character in the selection, the character right after the selection, and the largest font width of that selection, you should be able to determine the bounds of the box.

Then, just use the RichTextBox.CreateGraphics and draw the box. To clear it, just invalidate the RichTextBox.


这篇关于为所选文字添加边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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