Figure 1. Output result screen.
<code c#>
textBoxMultiLine.Text += "" + i + Environment.NewLine;
</code c#>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace forloop2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1Run_Click(object sender, EventArgs e)
{
//Check valid , Is start field empty ?
if (textBoxStart.Text.Trim() !="" && textBoxEnd.Text.Trim() !="")
{
// get values from start and stop
int start = int.Parse(textBoxStart.Text);
int stop = int.Parse(textBoxEnd.Text);
//check valid, is in 1-100 range allowed.
if (start >= 0 && stop <= 100)
{
//Start calculation with for loop command
for (int i = start; i <= stop; i++)
{
//Note: you must use operator [+= ""]
textBoxMultiLine.Text += "" + i + Environment.NewLine;
}
} else
{
textBoxMultiLine.Text = "Out of range, Check...\r\n";
}
}
else
{
textBoxMultiLine.Text = "Start or end value is empty.\r\n";
}
}
private void button2Clear_Click(object sender, EventArgs e)
{
textBoxMultiLine.Text ="";
}
private void textBoxMultiLine_TextChanged(object sender, EventArgs e)
{
}
}
}
Figure 2: Textbox properties
...
...
...
// textBoxMultiLine
//
this.textBoxMultiLine.Location = new System.Drawing.Point(231, 12);
this.textBoxMultiLine.Multiline = true;
this.textBoxMultiLine.Name = "textBoxMultiLine";
this.textBoxMultiLine.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBoxMultiLine.Size = new System.Drawing.Size(160, 111);
this.textBoxMultiLine.TabIndex = 8;
this.textBoxMultiLine.TextChanged += new System.EventHandler(this.textBoxMultiLine_TextChanged);
//
...
...
...
No comments:
Post a Comment