Add two Button and one Label in your Windows
Application Form.
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;
using
System.Diagnostics;
namespace
DynamicTexBox
{
public partial
class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
TextBox[] textBoxes;
private void
button1_Click(object sender,
EventArgs e)
{
int value = 3;
textBoxes =
new TextBox[value];
for (int i = 1;
i < value; i++)
{
textBoxes[i]
= new TextBox();
textBoxes[i].SetBounds(30,
i * 30, 60, 20);
this.Controls.Add(textBoxes[i]);
}
}
private void
button2_Click(object sender,
EventArgs e)
{
int myTotal = 0;
foreach (Control
ctl in this.Controls)
{
if (ctl.GetType() ==
typeof(TextBox))
{
myTotal
+= Convert.ToInt32(ctl.Text);
}
}
label1.Text =
myTotal.ToString();
}
}
}