首页 \ 问答 \ 编辑后保留突出显示的文本颜色(Retain highlighted color of text after editing)

编辑后保留突出显示的文本颜色(Retain highlighted color of text after editing)

在删除前面的行内容后,无法保留我在我的文本上设置的RichTextBox中突出显示的效果。

无论我从控件中删除多少文本,它总是删除自定义SelectionColor和SelectionBackColor我设置为已包含在其中的文本。

我的删除方法代码:

private void btnRemove_Click(object sender, EventArgs e)
{
    //Remove selected line from RichTextBox
    richTextBox1.Text = richTextBox1.Text.Remove(richTextBox1.Text.Length - 1, 1);
    //Remove all blank lines remaining after deletion                  
    richTextBox1.Text = Regex.Replace(richTextBox1.Text, @"^\s*$(\n|\r|\r\n)", "", RegexOptions.Multiline);
}

我想在这里删除的字母数是1,因为单词“AND”是通过剪贴板粘贴方法插入的简单图像。

在此处输入图像描述


Cannot keep the highlighted effect I set in my RichTextBox on my text after removing content of a line in front of him.

No matter how much text I remove from the control it always removes the custom SelectionColor and SelectionBackColor I set to a text already contained in it.

Code of my Removal method:

private void btnRemove_Click(object sender, EventArgs e)
{
    //Remove selected line from RichTextBox
    richTextBox1.Text = richTextBox1.Text.Remove(richTextBox1.Text.Length - 1, 1);
    //Remove all blank lines remaining after deletion                  
    richTextBox1.Text = Regex.Replace(richTextBox1.Text, @"^\s*$(\n|\r|\r\n)", "", RegexOptions.Multiline);
}

The number of letters I want to remove here is 1 as the word "AND" is a simple image inserted by means of Clipboard Paste method.

enter image description here


原文:https://stackoverflow.com/questions/37064223
更新时间:2022-04-20 10:04

最满意答案

我会使用https://github.com/yaronn/blessed-contrib它带有很多内置的小部件。


I would use https://github.com/yaronn/blessed-contrib it comes with a lot of widgets built-in.

相关问答

更多