RichTextBox:使用RichTextBox. selection .start等选项卡内容
本文关键字:RichTextBox 选项 start 使用 selection | 更新日期: 2023-09-27 18:09:23
我想给选定的文本加下划线,但发现下划线继续到下一个选项卡-停止
示例代码
//rtbList is a richTextBox
rtbList.AppendText("'t");
selStart = rtbList.TextLength;
rtbList.AppendText("Bought");
rtbList.SelectionStart = selStart;
rtbList.SelectionLength = rtbList.TextLength - selStart;
rtbList.SelectionFont = hdgFont; // bold & underline
rtbList.AppendText("'t");
//
selStart = rtbList.TextLength;
rtbList.SelectionLength = 0;
rtbList.AppendText("Maturity");
rtbList.SelectionStart = selStart;
rtbList.SelectionLength = rtbList.TextLength - selStart;
rtbList.SelectionFont = hdgFontNoUnderline;
是否有办法克服这个问题,或者这是rtf格式的一个基本"缺陷"?
显然,我可以通过使用固定的格式来避免这种情况。"Courier"和构造字符串看起来您的selStart发生在AppendText("'t")
行之前。您的下划线字体不包括包含制表符的范围。
基本上,任何你附加在下划线字体之后的文本都会得到那个字体,直到你改变它。
rtbList.AppendText("'t");
selStart = rtbList.TextLength;
rtbList.AppendText("Bought");
rtbList.SelectionStart = selStart;
rtbList.SelectionLength = rtbList.TextLength - selStart;
rtbList.SelectionFont = hdgFont; // bold & underline
//Move before AppendText:
selStart = rtbList.TextLength;
rtbList.AppendText("'t");
rtbList.SelectionLength = 0;
rtbList.AppendText("Maturity");
rtbList.SelectionStart = selStart;
rtbList.SelectionLength = rtbList.TextLength - selStart;
rtbList.SelectionFont = hdgFontNoUnderline;