如何在richTextBox1中添加行/字符串?

时间:2014-07-27 12:16:04

标签: c# winforms

ListsExtractions.text1包含49个项目 但最终richTextbox1是空的。 如何将ListsExtractions.text1中的字符串/行添加到richTextBox1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScrollLabelTest
{
    public partial class DisplayLockedThreads : Form
    {
        public DisplayLockedThreads()
        {
            InitializeComponent();

            for (int i = 0; i < ListsExtractions.text1.Count; i++)
            {
                richTextBox1.Text = ListsExtractions.text1[i];
            }
        }

        private void DisplayLockedThreads_Load(object sender, EventArgs e)
        {

        }
    }
}

ListsExtractions.text1包含49个项目 但最后richTextbox1是空的。

2 个答案:

答案 0 :(得分:3)

更改此

for (int i = 0; i < ListsExtractions.text1.Count; i++)
        {
            richTextBox1.Text = ListsExtractions.text1[i];
        }

到这个

richTextBox1.Text = String.Join(Environment.NewLine, ListsExtractions.text1 );

答案 1 :(得分:1)

我认为你是两次调用它,从构造函数移动到你的代码的加载事件:

   using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace ScrollLabelTest
    {
        public partial class DisplayLockedThreads : Form
        {
            public DisplayLockedThreads()
            {
                InitializeComponent();

            }

            private void DisplayLockedThreads_Load(object sender, EventArgs e)
            {
               richTextBox1.Text = String.Join(Environment.NewLine, ListsExtractions.text1 );    
            }
        }
    }