RTF代码中的插入号/选择位置 [英] Caret/Selection position within RTF code

查看:78
本文介绍了RTF代码中的插入号/选择位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我目前正在尝试使用粗体,上标等内容,以便在富文本框中格式化数据.

有谁知道如何在RTF代码中获得选择位置?
注意:我不是在TEXT中,而是在RTF中的位置.

例如,假设插入符号的位置在单词sat
的"a"和"t"之间 文字:
坐在在垫子上
RTF(大致):
我/b sat/b0在垫子上

选择位置将返回4,因为它在TEXT中排在第四位.
我想返回7,因为那是RTF代码中插入符号的位置.

仅供参考,我是因为我没有使用以下代码:

Hi guys,
I''m currently trying to use bolding, superscript etc in order to format data in a rich textbox.

Does anyone know how to get the selection position within the RTF code??
NB i DON''T mean within the TEXT, but rather where in the RTF.

e.g Say the caret position was between the ''a'' and the ''t'' in the the word sat
Text:
I sat on the mat
RTF (roughly):
I /b sat/b0 on the mat

Selection position would return 4 because it''s the fourth place in the TEXT.
I would want to have 7 returned, because that''s where the caret is in the RTF code.

FYI i reason I''m not using code like:

FontStyle style2Add = aRichTextBox.SelectionFont.Style ^ FontStyle.Bold;
aRichTextBox.SelectionFont = new Font(aRichTextBox.SelectionFont, style2Add | (aRichTextBox.SelectionFont.Style ^ FontStyle.Bold));


这是因为,如果您选择的字词结尾处的格式 tted 完全不同,那么它倾向于清除其他格式.当您突出显示很多文本(我已经尝试过)时,逐个字母地格式化单词(大约是每个字符的上述循环)太慢了.

那么,问题又来了:有人知道如何在RTF代码中获得选择位置吗?

谢谢!


is because it has a lovely tendency to wipe out other formatting if you have selected a word which is formatted differently at the end. Formatting words on a letter-by-letter basis (which roughly would be a loop of the above for each character) is simply too slow when you have a lot of text highlighted (i''ve tried it).

So, the question again: Does anyone know how to get the selection position within the RTF code??

Thanks!

推荐答案

您尝试使用SelectedRtf属性吗?
摘要:
获取或设置控件中当前选定的RTF格式的文本.
返回:
控件中选定的RTF文本.

Havge you tried the SelectedRtf property?
Summary:
Gets or sets the currently selected rich text format (RTF) formatted text in the control.
Returns:
The selected RTF text in the control.

Can you not work with that, rather then trying to find the position?


关于使用这种方法在光标位置插入标签的任何想法?
我可以使用richtextbox.selectedRTF属性更改字体,并输入标签,例如"//super"(上标)等,效果很好.

例如
Any ideas on inserting tags at the cursor position with such a method??

I can use the richtextbox.selectedRTF property to change the font, and input tags such as "//super " (superscript) and so on, which works great.

e.g.
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang5129{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\r\n\\uc1\\pard\\fs24 Some Selected Text!}\r\n"


*插入超级脚本标签*


*INSERT SUPERSCRIPT TAG*

"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang5129{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}\r\n\\uc1\\pard\\super\\fs24 Some Selected Text!}\r\n"



但是,如果没有突出显示文本,则无法在插入符号的位置插入格式,因为selectedRTF看起来像这样:



However, if no text is highlighted, I have no way of inserting formatting at the caret position, because the selectedRTF looks something like this:

"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang5129\\uc1 }\r\n"



如果您按下上标"按钮,即使没有选择任何内容,您也希望能够键入上标.
有关在光标位置插入标签的任何想法?

在这里撕扯我的头发:s



if you pressed the ''superscript'' button, you''d expect to be able to type in superscript, even if nothing around was selected.
Any ideas on inserting tags at the cursor position??

Tearing my hair out here :s


这篇关于RTF代码中的插入号/选择位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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