大家请顶,如何动态加载form窗体?   
  已知窗体名叫:   
  "Form1"   
  "Form2"
  "Form3" 
string form2 = "Form2";
string from3 = "Form3";如何动态加载阿?最终的目的是用于数据库记录窗体名称,动态加载谢谢  

解决方案 »

  1.   

    Form Form1 = new Form();
    Form1.Show();
    其他的一样
      

  2.   

    不好意思,我是说Form名称将是字符串从数据库出来的
      

  3.   

    用反射
    先写个类库,然后加载。如:
    Form form = (Form)System.Reflection.Assembly.Load("类库名").CreateInstance("类名");
                form.ShowDialog();
      

  4.   

    是哦..
    用Activator.CreateInstance (Type) 创建好了.
    如果是固定的这三个窗体的话,,用一个switch也好啊
      

  5.   

    private void jstzdfile_add_Click(object sender, System.EventArgs e)  //增加新节点jstzdfile_add
    {    Form createbdselectfrm = new Form();
                   createbdselectfrm.ClientSize= new System.Drawing.Size(300,300);
                   createbdselectfrm.Location = new System.Drawing.Point(100,50);    Label  Label1 = new Label();
       Label1.Location= new System.Drawing.Point(24,24);
       Label1.Text = "请输入技术通知单的文件名:";
       Label1.Size = new System.Drawing.Size(168,23);               TextBox TextBox1 = new TextBox();
                   TextBox1.Location= new System.Drawing.Point(80,64);
       TextBox1.Size = new System.Drawing.Size(100,20);
       Button  Button1 = new Button();
                   Button1.Location = new System.Drawing.Point(75,260);
                   Button1.Size = new System.Drawing.Size(100,20);
                   Button1.Text="确定";
                   Button1.DialogResult = System.Windows.Forms.DialogResult.OK;
       createbdselectfrm.Controls.Add(Label1);
       createbdselectfrm.Controls.Add(TextBox1);
       createbdselectfrm.Controls.Add(Button1);
       createbdselectfrm.StartPosition = FormStartPosition.CenterScreen;   DialogResult res = createbdselectfrm.ShowDialog();
    if( res ==System.Windows.Forms.DialogResult.OK && TextBox1.Text!="" ) 
    {                jstzd_bianhao=TextBox1.Text.ToString().Trim().ToLower();
                    //add_nodetext = TextBox1.Text.ToString().Trim().ToLower();
                    nodeatr="技术通知单";
    strnzjswj="技术通知单";
                    strjdhswj="0";
                    createbdselectfrm.Close(); DataTable tempTable = new DataTable(); this.strSQL = "select jstzd_bianhao from jstzd where jstzd_bianhao = '" + jstzd_bianhao + "'";
    this.da = new SqlDataAdapter(this.strSQL,this.tempConnection);
    this.da.Fill(tempTable);//查询获得机构的单位名称,并填写到文本框中
    if (tempTable.Rows.Count==0)
    {
    AddRecord(false,"jstzd");
                            
             new_open_del_ren = "jstzd_new"; jstzd jstzdMDIChild = new jstzd();
    jstzdMDIChild.MdiParent = this;
    jstzdMDIChild.Show();
    }
    else
                            MessageBox.Show ("库中已存在");
    }  }
    以上代码从我代码里复制出,意思是在屏幕中间动态添加一窗口,输入树节点的名称.......
      

  6.   

    不是固定的,就是从数据库出来的。能给具一个例子么,没看懂。例如:
    string form1name = "Form1"Form form = (Form)System.Reflection.Assembly.Load(LibName).CreateInstance(form1name);
                form.ShowDialog();
      

  7.   

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;namespace WindowsApplication2
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                string form1 = "Form1";
                Application.Run((Form)Activator.CreateInstance(Type.GetType("WindowsApplication2" + "." + form1)));
            }
        }
    }
      

  8.   

    建议在数据库中存储Form窗体的包涵命名空间的类型名称,甚至是包括所在dll,比如:
    "System.Windows.Forms.Form,System.Windows.Forms"