[英]How to change Symbol Number to Upper Case… in the “richTextBox.Lines” array?
[英]How to change the format of specified lines in a RichTextBox
我有一個winforms RichTextBox包含許多行文本(例如2 MB文本文件),並希望以編程方式更改指定行的格式,例如突出顯示它們。
我該如何處理線條而不是字符? RichTextBox甚至是對這類事情的最佳控制,還是有另一種選擇? 我已經嘗試過Infragistics UltraFormattedTextEditor,但顯示文本的速度至少要低幾個數量級,因此對於我的較長文件沒有任何好處。
謝謝!
要訪問文本框控件上的行,請使用Lines屬性
richTextBox.Lines
從那里你可以遍歷這些線並使用你想要改變的線。
編輯:同意,我錯過了重點部分(+1回答你自己的問題)。 包括工作代碼:
int lineCounter = 0;
foreach(string line in richTextBox1.Lines)
{
//add conditional statement if not selecting all the lines
richTextBox.Select(richTextBox.GetFirstCharIndexFromLine(lineCounter), line.Length);
richTextBox.SelectionColor = Color.Red;
lineCounter++;
}
好的,我將記錄我找到的解決方案:使用richTextBox.Lines
來獲取Luis所說的那些行
richTextBox.GetFirstCharIndexFromLine(int line)
richTextBox.Select(int start, int length)
然后選擇相關的行
richTextBox.SelectionColor...
richTextBox.SelectionBackground...
格式化線條等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.