大家请顶,如何动态加载form窗体?
已知窗体名叫:
"Form1"
"Form2"
"Form3"
string form2 = "Form2";
string from3 = "Form3";如何动态加载阿?最终的目的是用于数据库记录窗体名称,动态加载谢谢
已知窗体名叫:
"Form1"
"Form2"
"Form3"
string form2 = "Form2";
string from3 = "Form3";如何动态加载阿?最终的目的是用于数据库记录窗体名称,动态加载谢谢
解决方案 »
- 动态生成表格后,如何激发控件事件?
- 高分求提示 ContextMenuStrip的问题
- 各位求助 为什么导出数据库成外界EXCEL会出错 谢谢了
- 如何把DataGrid里面的数据保存成xml
- 我用COM+组件为什么就是连不上数据库 请高手指教~~~!拜托~~~!
- 请教一个关于crystal report比较无知的问题
- 如何管理众多的控件?(c#winform)
- 什么时候,继承接口的函数需要加上接口的名字?
- 招聘.NET程序员
- 如何使用Microsoft Visual C# .net(ADO.NET对加密过的数据库进行访问
- 请问哪位大侠晓得什么地方有C#的C/S源码下载
- 比较急的问题:关于C/S 树形结构
Form1.Show();
其他的一样
先写个类库,然后加载。如:
Form form = (Form)System.Reflection.Assembly.Load("类库名").CreateInstance("类名");
form.ShowDialog();
用Activator.CreateInstance (Type) 创建好了.
如果是固定的这三个窗体的话,,用一个switch也好啊
{ 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 ("库中已存在");
} }
以上代码从我代码里复制出,意思是在屏幕中间动态添加一窗口,输入树节点的名称.......
string form1name = "Form1"Form form = (Form)System.Reflection.Assembly.Load(LibName).CreateInstance(form1name);
form.ShowDialog();
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)));
}
}
}
"System.Windows.Forms.Form,System.Windows.Forms"