1. <i id='GQoII'><tr id='GQoII'><dt id='GQoII'><q id='GQoII'><span id='GQoII'><b id='GQoII'><form id='GQoII'><ins id='GQoII'></ins><ul id='GQoII'></ul><sub id='GQoII'></sub></form><legend id='GQoII'></legend><bdo id='GQoII'><pre id='GQoII'><center id='GQoII'></center></pre></bdo></b><th id='GQoII'></th></span></q></dt></tr></i><div id='GQoII'><tfoot id='GQoII'></tfoot><dl id='GQoII'><fieldset id='GQoII'></fieldset></dl></div>
    2. <small id='GQoII'></small><noframes id='GQoII'>

        <tfoot id='GQoII'></tfoot>
        • <bdo id='GQoII'></bdo><ul id='GQoII'></ul>

        <legend id='GQoII'><style id='GQoII'><dir id='GQoII'><q id='GQoII'></q></dir></style></legend>

        如何在多行文本框中添加一行?

        时间:2023-06-10
            <tbody id='wOD21'></tbody>
                <bdo id='wOD21'></bdo><ul id='wOD21'></ul>

              • <tfoot id='wOD21'></tfoot>
                  <legend id='wOD21'><style id='wOD21'><dir id='wOD21'><q id='wOD21'></q></dir></style></legend>

                1. <i id='wOD21'><tr id='wOD21'><dt id='wOD21'><q id='wOD21'><span id='wOD21'><b id='wOD21'><form id='wOD21'><ins id='wOD21'></ins><ul id='wOD21'></ul><sub id='wOD21'></sub></form><legend id='wOD21'></legend><bdo id='wOD21'><pre id='wOD21'><center id='wOD21'></center></pre></bdo></b><th id='wOD21'></th></span></q></dt></tr></i><div id='wOD21'><tfoot id='wOD21'></tfoot><dl id='wOD21'><fieldset id='wOD21'></fieldset></dl></div>

                  <small id='wOD21'></small><noframes id='wOD21'>

                  本文介绍了如何在多行文本框中添加一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在 多行 文本框?

                  例如伪代码;

                  textBox1.Clear();
                  textBox1.Lines.Add("1000+");
                  textBox1.Lines.Add("750-999");
                  textBox1.Lines.Add("400-749");
                  ...snip...
                  textBox1.Lines.Add("40-59");
                  

                  textBox1.Lines.Append("brown");
                  textBox1.Lines.Append("brwn");
                  textBox1.Lines.Append("brn");
                  textBox1.Lines.Append("brow");
                  textBox1.Lines.Append("br");
                  textBox1.Lines.Append("brw");
                  textBox1.Lines.Append("brwm");
                  textBox1.Lines.Append("bron");
                  textBox1.Lines.Append("bwn");
                  textBox1.Lines.Append("brnw");
                  textBox1.Lines.Append("bren");
                  textBox1.Lines.Append("broe");
                  textBox1.Lines.Append("bewn");
                  

                  TextBox.Lines 实现(我可以看到)是:

                  The only methods that TextBox.Lines implements (that i can see) are:

                  • 克隆
                  • 复制到
                  • 等于
                  • 获取类型
                  • GetHashCode
                  • 获取枚举器
                  • 初始化
                  • GetLowerBound
                  • GetUpperBound
                  • 获取长度
                  • GetLongLength
                  • 获取值
                  • 设置值
                  • ToString

                  推荐答案

                  @Casperah 指出我想错了:

                  @Casperah pointed out that i'm thinking about it wrong:

                  • TextBox 没有
                  • 它有文字
                  • 如果需要,该文本可以在 CRLF 上拆分成行
                  • 但没有
                  • 的概念
                  • A TextBox doesn't have lines
                  • it has text
                  • that text can be split on the CRLF into lines, if requested
                  • but there is no notion of lines

                  那么问题是如何完成我想要的,而不是 WinForms 让我做什么.

                  The question then is how to accomplish what i want, rather than what WinForms lets me.

                  在其他给定的变体中存在细微的错误:

                  There are subtle bugs in the other given variants:

                  • textBox1.AppendText("Hello" + Environment.NewLine);
                  • textBox1.AppendText(Hello"+ ");
                  • textBox1.Text += "Hello "
                  • textbox1.Text += System.Environment.NewLine + "brown";
                  • textBox1.AppendText("Hello" + Environment.NewLine);
                  • textBox1.AppendText("Hello" + " ");
                  • textBox1.Text += "Hello "
                  • textbox1.Text += System.Environment.NewLine + "brown";

                  当(可能)不需要时,它们会附加或添加换行符.

                  They either append or prepend a newline when one (might) not be required.

                  所以,扩展助手:

                  public static class WinFormsExtensions
                  {
                     public static void AppendLine(this TextBox source, string value)
                     {
                        if (source.Text.Length==0)
                           source.Text = value;
                        else
                           source.AppendText("
                  "+value);
                     }
                  }
                  

                  那么现在:

                  textBox1.Clear();
                  textBox1.AppendLine("red");
                  textBox1.AppendLine("green");
                  textBox1.AppendLine("blue");
                  

                  textBox1.AppendLine(String.Format("Processing file {0}", filename));
                  

                  注意:任何代码都会发布到公共领域.无需署名.

                  Note: Any code is released into the public domain. No attribution required.

                  这篇关于如何在多行文本框中添加一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:输入按键事件处理程序 下一篇:将 ASP.NET 文本框呈现为 HTML5 输入类型“数字"

                  相关文章

                  1. <small id='JVhQ2'></small><noframes id='JVhQ2'>

                  2. <tfoot id='JVhQ2'></tfoot>
                    <i id='JVhQ2'><tr id='JVhQ2'><dt id='JVhQ2'><q id='JVhQ2'><span id='JVhQ2'><b id='JVhQ2'><form id='JVhQ2'><ins id='JVhQ2'></ins><ul id='JVhQ2'></ul><sub id='JVhQ2'></sub></form><legend id='JVhQ2'></legend><bdo id='JVhQ2'><pre id='JVhQ2'><center id='JVhQ2'></center></pre></bdo></b><th id='JVhQ2'></th></span></q></dt></tr></i><div id='JVhQ2'><tfoot id='JVhQ2'></tfoot><dl id='JVhQ2'><fieldset id='JVhQ2'></fieldset></dl></div>
                  3. <legend id='JVhQ2'><style id='JVhQ2'><dir id='JVhQ2'><q id='JVhQ2'></q></dir></style></legend>

                        <bdo id='JVhQ2'></bdo><ul id='JVhQ2'></ul>