新行添加到Rich TextBox中的文本末尾

时间:2012-10-17 07:46:02

标签: c# richtextbox

我的表单中有一个富文本框(WinForm)。我用它来更新描述列。当我执行更新操作时,它会在最后引入换行符或换行符。

如何以简单的方式避免使用此换行符。是需要通过代码处理还是通过财产管理?

public MyDlg(string strXmlFile)
{
    InitializeComponent();

    strInputXmlFile = strXmlFile;

    xmlDoc.Load(@"c:\temp\SBD_Input.xml");
    node = xmlDoc.SelectSingleNode("//SBD/Description");

    // Set the description into the rich text box.
    richTextBox1.AppendText(node.InnerText);
}

private void UpdateBtn_Click(object sender, EventArgs e)
{
    // Put the RTB contents back into node & Import.
    node.InnerText = richTextBox1.Text;
    xmlDoc.ImportNode(node, true);

    // Save the Xml document.
    xmlDoc.Save(@"c:\temp\SBD_Input.xml");

    this.Close();
}

输入XML文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<SBD>
  <Number> 1234567</Number>
  <Description>EDGES MAY BE BROKEN
  All surfaces are varnished
            --------------------
  Color     |  R  |  G  |  B  |
            -------------------- 

  as dflkjaslödfj lasöj flöaskj flaksjd fölkasjd flöaskjdf 
   askjflj asld fjklöaskjdf laskjfl s falsj flöasjkd f flaskjdf a 
  as djflajs dfl

  </Description>
</SBD>

enter image description here

1 个答案:

答案 0 :(得分:0)

在更新btn代码中尝试此操作:

node.InnerText = richTextBox1.Text.TrimEnd( '\r', '\n' ); 
相关问题