gpt4 book ai didi

c# - TextBox 中不显示换行符

转载 作者:数据小太阳 更新时间:2023-10-29 02:40:14 24 4
gpt4 key购买 nike

我有一个如下图所示的表格:

enter image description here

现在,当用户点击 Save As Template 时,我将文本框的文本保存在 XML 文件中。我用来将此文本保存在 XML 文件中的代码是:

public static void SaveTemplate(string Message)
{
XDocument xmlDocument = XDocument.Load(templatesPath);

xmlDocument.Element("Templates").Add(
new XElement("Template", new XAttribute("Id", xmlDocument.Root.Elements("Template").LastOrDefault() != null ? int.Parse(xmlDocument.Root.Elements("Template").LastOrDefault().Attribute("Id").Value) + 1 : 1),
new XElement("Body", Message)));

xmlDocument.Save(templatesPath);
}

保存在 XML 文件中的文本如下所示:

enter image description here

之后用户可以做任何他想做的事。当用户再次运行我的应用程序时,文本框为空。因此,他将单击 Load Template 按钮。那时文本显示在datagridview中:

enter image description here

现在,用户点击Select Template,DataGridViewCell 中的文本再次被复制到文本框。但文本不包含换行符。请看下图:

enter image description here

过去有没有人遇到过同样的问题?

最佳答案

我只需将 \n 替换为 Environment.NewLine,例如:

_frmMsgDetails.MessageBody = dgvTemplates.SelectedRows[0].Cells[2].Value.ToString()
.Replace("\n", Environment.NewLine);

关于c# - TextBox 中不显示换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29178198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com