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 =
will replace the entire string, including newlines.You need to add to
Result.Text
instead of replacing it.Before the
for
loop, initialize it to an empty string:Then below that point, always append rather than replacing, e.g.
Instead of
And so on.