I've to create three textboxes when clicked on Add button. Initially I tried to generate a single textbox but can not do the same. I took help from this forum as well as , http://csharp.net-informations.com/gui/dynamic-controls-cs.htm.
I can not see any textboxes when clicked on Add button.
namespace DataDashBoard.UI
{
public partial class DataForm : Form
{
int cLeft = 1;
public DataForm()
{
InitializeComponent();
}
public TextBox AddNewTextBox()
{
TextBox txt = new TextBox();
this.Controls.Add(txt);
txt.Top = cLeft * 25;
txt.Left = 100;
txt.Text = "TextBox " + this.cLeft.ToString();
cLeft = cLeft + 1;
return txt;
}
private void btnAdd_Click(object sender, EventArgs e)
{
AddNewTextBox();
}
}
}
Please help!!!