using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Collections.Specialized;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Threading;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public static string configFileExe = ConfigurationManager.AppSettings["configFileExe"];
public Form1()
{
InitializeComponent();
}
public string[] TabKeys;
public string[] TabValues;
public void readAppConfig()
{
Configuration configFile = ConfigurationManager.OpenExeConfiguration(@configFileExe);
TabKeys = configFile.AppSettings.Settings.AllKeys.ToArray();
List<string> values = new List<string>();
for (int cpt=0; cpt < TabKeys.Length; cpt++)
{
string value = configFile.AppSettings.Settings[TabKeys[cpt]].Value.ToString();
values.Add(value);
}
TabValues = values.ToArray();
}
private void Form1_Load(object sender, EventArgs e)
{
readAppConfig();
createTxtBoxes();
}
public void createTxtBoxes()
{
TextBox[] txtBoxes = new TextBox[TabKeys.Length];
Label[] labels = new Label[TabValues.Length];
for (int u = 0; u < txtBoxes.Count(); u++)
{
txtBoxes[u] = new TextBox();
labels[u] = new Label();
}
for(int i = 0; i< txtBoxes.Count(); ++i)
{
string nameTxtBox = TabKeys[i].ToString();
txtBoxes[i].Name = nameTxtBox;
txtBoxes[i].Text = nameTxtBox;
txtBoxes[i].Location = new Point(350, 32 + (i * 28));
Size size = TextRenderer.MeasureText(txtBoxes[i].Text, txtBoxes[i].Font);
txtBoxes[i].Width = size.Width;
txtBoxes[i].Height = size.Height;
txtBoxes[i].Visible = true;
string nameLabel = TabValues[i].ToString();
labels[i].Name = nameLabel;
labels[i].Text = nameLabel;
labels[i].AutoSize = true;
labels[i].Location = new Point(32, 32 + (i * 28));
labels[i].Visible = true;
this.panel1.Controls.Add(labels[i]);
this.panel1.Controls.Add(txtBoxes[i]);
}
}
}
}