标签:实例化 method str 检查 空间 click try object get
根据窗体名称创建窗体;
/// <summary>
/// 手动根据窗体名称创建窗体;
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
string str = "命名空间名:" + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace + "\n";
label1.Text = str;
Assembly assembly = Assembly.GetExecutingAssembly();
// 实例化窗体
try
{
Form form = assembly.CreateInstance("DataCollection.UserInofFrm") as Form; //命名空间+窗体名称
form.ShowDialog();
}
catch (Exception)
{
MessageBox.Show("窗体创建失败,请检查窗体名称是否正确!");
}
}

标签:实例化 method str 检查 空间 click try object get
原文地址:https://www.cnblogs.com/nymz/p/14051745.html