首页 > 解决方案 > 如何将具有 CR\LF 的字符串变量设置到 Winform 文本框中?

问题描述

我有一个 Winforms 文本框设置为 AcceptReturns = true,Scrollbars = vertical,Multiline = true。我通过循环遍历数据表来构造一个名为 note 的字符串,将值放入 note 中:note = note 加上“\n\n”。当我使用文本可视化工具查看字符串时,它正确显示了 CR\LF,但在命令之后:remarks.text = note,文本框没有 CR\LF。如何让 CR\LF 得到尊重?

                int x = 0;
                string note = "";
                command = null;
                DataTable dtnew = new DataTable();
                foreach (string rcd in app.feecd) // app.feecd is an array established earlier in code
                {
                    command = GetConnectedClass.newsqlconnection("SELECT NoteDesc from dbo.inspnote where NoteCode = @selcode");
                    command.Parameters.AddWithValue("@selcode", rcd);
                    dtnew.Load(command.ExecuteReader());
                    note = note + dtnew.Rows[x].Field<string>("NoteDesc") + "\n\n";
                    command = null;
                    x = x + 1;
                }

                if (remarks.Text == "")
                { remarks.Text = note; } // note has CR\LF but remarks.Text NO CR\LF ????
                else { remarks.Text = remarks.Text + "\n\n" + note; }

标签: c#winforms

解决方案


推荐阅读