为什么当我的Window Forms应用程序出现循环时,我只能看到一些文本输出? [英] Why do I only see some of my text output when my Window Forms application has a loop?
问题描述
我试图提供两个数字(最大值和最小值)来创建乘法表.我当前的代码可以在控制台中完美运行,但是无法将其正确打印到Windows Forms Applications中的文本框中.我只能打印一个最大的数字.
Im trying to provide two numbers, a maximum and minimum, to create a multiplication table. My current code works perfectly in console, but I cant get it to properly print to a text box in Windows Forms Applications. I only manage to print a single, maximum, number.
private void MultiTab_CheckedChanged(object sender, EventArgs e)
{
string final = "The Multiplication Table Is:";
int i = Convert.ToInt32(Max.Text);
int k = Convert.ToInt32(Min.Text);
for (i = 1; i <= k; i++)
{
Result.Text = (i + "\t");
for (int j = 1; j <= k; j++)
{
string x;
if (i > k) x = i * j + "\t";
else x = j + "\t";
Result.Text = final + x;
}
Result.Text = ("\n");
}
}
推荐答案
Result.Text =
将替换整个字符串,包括换行符.
Result.Text =
will replace the entire string, including newlines.
您需要添加到Result.Text
而不是替换它.
You need to add to Result.Text
instead of replacing it.
在for
循环之前,将其初始化为空字符串:
Before the for
loop, initialize it to an empty string:
Result.Text = "";
然后在该点以下,始终添加而不是替换,例如
Then below that point, always append rather than replacing, e.g.
Result.Text += (i + "\t");
代替
Result.Text = (i + "\t");
以此类推.
这篇关于为什么当我的Window Forms应用程序出现循环时,我只能看到一些文本输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!