用反射:
主调类:
private void button3_Click(object sender, EventArgs e)
{
bindForm("WindowsApplication1.UserControl1");
}
private void bindForm(string f)
{
System.Type t = System.Type.GetType(f);
object ff = Activator.CreateInstance(t,null);
System.Reflection.MethodInfo method = t.GetMethod("setText");
System.Reflection. BindingFlags flag = System.Reflection. BindingFlags.Public |System.Reflection. BindingFlags.Instance;
object returnValue = method.Invoke(ff, null);
}
各窗体:
public partial class UserControl1 : Form
{
public UserControl1()
{
InitializeComponent();
}
public void setText()
{
Text = "kkk";
Show();
}
}