StringBuilder 不会显示在文本框中(WinForms,C#) [英] StringBuilder Won't Show In TextBox (WinForms, C#)

查看:32
本文介绍了StringBuilder 不会显示在文本框中(WinForms,C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让 StringBuilder 的内容显示在 WinForms 文本框中,但是当我尝试编译程序时该窗口从未出现.这是我第一次尝试使用 WinForms 和 C#,我现在只使用了大约一个半星期的时间,所以这可能是一个我没有看到的简单修复.

I'm trying to get the contents of a StringBuilder to display in a WinForms textbox, but the window never appears when I try to compile the program. This is my first venture into WinForms and C# and I've only used the language for about a week and a half now, so this is probably a simple fix that I'm just not seeing.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        StringBuilder builder = new StringBuilder();
        Random rand = new Random();
        int[] builderList = new int[10000];
        for (int i = 0; i < 10000; i++)
        {
            builderList[i] = rand.Next(1, 20000);
            builder.Append(builderList[i].ToString() + " ");
        }

        // This is the line that seems to be the problem...
        textBox1.Text = builder.ToString(); 
    }
}

当我尝试运行该程序并在最后一行代码上插入断点时,我可以看到该程序似乎只是连续命中该行.奇怪的是,如果我将该行更改为:

When I try to run the program and insert a breakpoint on that last line of code, I can see that the program seems to just hit that line continuously. Oddly enough, if I change that line to this:

textBox1.Text = "Hey, lol";

我的程序将运行.我检查了 Visual Studio 中的调试器,看到builderList"的内容更新为随机数,builder"看起来像我想要的那样正确地将builderList"中的值存储为字符串,所以我有点困惑关于这里发生了什么.我很感激我能得到的任何帮助,因为它看起来应该是一个相对容易的修复,但到目前为止我一直被它难住了,我还没有在 MSDN 文档中找到任何有用的东西.

my program will run. I checked the debugger in Visual Studio and saw that the contents of 'builderList' are updated to random numbers and 'builder' looks like it's correctly storing the values in 'builderList' as a string like I want, so I'm kind of confused about what's going on here. I'd appreciate any help I can get on this one as it seems like it should be a relatively easy fix but I've been stumped on it so far and I haven't really found anything helpful in the MSDN documentation.

非常感谢!

推荐答案

将你的 TextBox1 改为 MultiLine TextBox.Select "Allow multiLine"

Change your TextBox1 to be a MultiLine TextBox.Select "Allow multiLine"

这篇关于StringBuilder 不会显示在文本框中(WinForms,C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆