public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public EntityMan GetEntity()
{
EntityMan man = new EntityMan();
man.Age = 12;
man.Address = "No.25";
man.Kind = "Asia";
man.Name = "WangXiaoyu";
man.PersonID = 110;
return man;
}
private void button1_Click(object sender, EventArgs e)
{
EntityMan man = GetEntity();
PropertyInfo[] properties = typeof(EntityMan).GetProperties();
for (int i = 0; i < properties.Length; i++)
{
string fn = properties[i].Name;
PropertyInfo pinfo = typeof(EntityMan).GetProperty(fn);
object obj = pinfo.GetValue(man, null);
string Value = obj.ToString();
string ControlName = "tb_" + fn;
System.Windows.Forms.Control c = gB.Controls[ControlName];//gb为groupbox
if (c != null)
{
int n = int.Parse(c.Tag.ToString());
switch (n)
{
case 0:
(c as TextBox).Text = Value;
break;
case 1:
(c as ComboBox).Text = Value;
break;
case 2:
break;
}
}
}
}