try
{
XmlDocument doc = new XmlDocument();
doc.Load(AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\XMLFileWindow.xml");
XmlNodeList nodes = doc.SelectNodes("/Label");
Assembly myAssembly = null;
myAssembly = Assembly.GetCallingAssembly();
foreach (XmlNode node in nodes)
{
try
{
Type tControl = myAssembly.GetType("System.Windows.Forms." + node.Name);
object objControl = Activator.CreateInstance(tControl, null);
foreach (XmlAttribute at in node.Attributes)
{
PropertyInfo p = tControl.GetProperty(at.Name);
if (p.Name == "Location")
{
string[] chLocation = at.Value.Split(',');
p.SetValue(objControl, new Point(Convert.ToInt16(chLocation[0].ToString()), Convert.ToInt16(chLocation[1].ToString())), null);
}
else if (p.Name == "Size")
{
string[] chLocation = at.Value.Split(',');
p.SetValue(objControl, new Size(Convert.ToInt16(chLocation[0].ToString()), Convert.ToInt16(chLocation[1].ToString())), null);
}
else if (p.Name == "TextAlign")
p.SetValue(objControl, HorizontalAlignment.Center, null);
else
p.SetValue(objControl, at.Value, null);
}
this.Controls.Add((Control)objControl);
}
catch (Exception exx)
{
Console.WriteLine(exx.Message);
return;
}
Good luck if it is helpfull.