建一个哈希表 Hashtable h = new Hashtable(); Form f1=new Form(); f1.Name="form1"; Form f2=new Form(); f2.Name="form2"; h.Add(f1.Name, f1); h.Add(f2.Name, f2); ((Form)h[textBox1.Text]).Show();
foreach (Form f in Application.OpenForms) { if (f.Name.IndexOf(textBox1.Text) > 0) f.Activate(); }
fm.Show();
static extern IntPtr FindWindow(string ClassName, string WindowName); private void button1_Click(object sender, EventArgs e)
{
IntPtr handle = FindWindow(null, textBox1.Text);
Form findform = Form.FromHandle(handle) as Form;
findform.Text = "找到的窗口";
}
Form f1=new Form();
f1.Name="form1";
Form f2=new Form();
f2.Name="form2";
h.Add(f1.Name, f1);
h.Add(f2.Name, f2); ((Form)h[textBox1.Text]).Show();
{
if (f.Name.IndexOf(textBox1.Text) > 0)
f.Activate();
}
怎样在一个TextBox中输入窗口名(例如:"Form093"),点击按钮后
直接就可以打开一个新的窗口Form093 ?
private void button1_Click(object sender, System.EventArgs e)
{
Form a=new Form();
string s1=(string.Format(this.textBox1.Text,a));
a.ShowDialog();
}
{
Form a=new Form();
string s1=(string.Format(this.textBox1.Text,a));
a.ShowDialog();
}==> 不行,只是打开一个新窗口,没有打开Form093foreach (Form f in Application.OpenForms)
{
if (f.Name.IndexOf(textBox1.Text) > 0)
f.Activate();
}
==> 不是让窗口成为活动窗口,而是打开建一个哈希表 Hashtable h = new Hashtable();
Form f1=new Form();
f1.Name="form1";
Form f2=new Form();
f2.Name="form2";
h.Add(f1.Name, f1);
h.Add(f2.Name, f2); ((Form)h[textBox1.Text]).Show();
==> 如果有200个窗口,要注册200次,不好!请问还有没有更好的方法???
Form093 fm=new Form093();
fm.Show();
Form f = Activator.CreateInstance(type);f.show();
...
// formName 必须是命名空间+formName
Type type = Type.GetType(formName);
object obj = Activator.CreateInstance(Type.GetType(formName));
this._additionForm = (Form)obj;