1. 程式人生 > >利用反射開啟新視窗

利用反射開啟新視窗

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"; } } } }