利用反射打开新窗口

using System.Reflection;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        int Value
        {
            get;
            set;
        }
        public Form1()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, EventArgs e)
        {
            label1.Text = "";
            Assembly assembly = Assembly.GetExecutingAssembly();
            try
            {
                Form f = assembly.CreateInstance("WindowsFormsApp1." + "Form" + textBox1.Text) as Form;
                f.ShowDialog();
            }
            catch(System.NullReferenceException)
            {
                label1.Text = textBox1.Text + " not exist";
            }
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/jizhiqiliao/p/9807782.html