I am assuming this is a Windows Application. To get and set Application Settings in this type of application you use
Properties.Settings.Default.yourSettingName
. Thus for your example you would need to do something like this:
private void btnAddTextBox_Click(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.Top = btnAddTextBox.Top;
tb.Left = btnAddTextBox.Left + btnAddTextBox.Width + 5;
tb.Visible = true;
tb.Name = "dynamicText";
this.Controls.Add(tb);
}
private void btnSaveToSettings_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl is TextBox)
{
if (ctrl.Name == "dynamicText")
{
Properties.Settings.Default.dynamicText = ctrl.Text;
}
}
}
}
private void btnRetrieveFromSettings_Click(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if (ctrl is TextBox)
{
if (ctrl.Name == "dynamicText")
{
ctrl.Text = Properties.Settings.Default.dynamicText;
}
}
}
}
This assumes you have a setting in your app.config file called
dynamicText
Hope this helps