求救阿:
各位高手帮帮忙,问题解决,马上结贴
例如我在button1 但击事件中显示了一个窗体newfrm如何在button2 的单击事件中修改newfrm的Text 属性>???

解决方案 »

  1.   

    例子:设有MainForm和BasicInfo两个窗体。修改一下BasicInfo窗口的构造函数,将MainForm的实例作为一个参数传递给BasicInfo,然后BasicInfo关闭时就可以引用原来那个MainForm了。
    例如:
    在MainForm中的:
    private void button2_Click(object sender, System.EventArgs e)
    {
    this.Hide();
    BasicInfo frm=new BasicInfo(this);
    frm.ShowDialog();
    }
    在BasicInfo.cs中:
    public class BasicInfo
    {
    ……
    private MainForm parentForm;
    ……
    public BasicInfo(MainForm frm)
    {
       parentForm = frm;
    }
    ……
    private void button12_Click(object sender, System.EventArgs e)
    {
    this.Close();
    parentForm.ShowDialog();//这里也可以引用parentForm的其它属性}
    }
      

  2.   

    晕,这么简单!
    Form1是主窗体
    Form2是被调用的窗体
    在Form1中设置一个全局变量Form1 form1=null;
    然后button1事件form2=new Form2();
    form2.show();
    button2时间form2.Text="love";
    一切OK
      

  3.   

    可是如果我单击了击次button1 ,然后就会打开几个form1 的实例,如何捕捉其中的一个 啊??
      

  4.   

    form1.Owner = this;void OnButton1Click(...)
    {
          if(OwnerForms.Length > 0)
               return;
               ...
    }
      

  5.   

    谢谢 haiwangstar(八月桂花香) 指点:void OnButton1Click(...)
    {
          if(OwnerForms.Length > 0)
               return;
               ...
    }
    能解释一下OwnerForms 的含义嘛??
      

  6.   

    可是如果我单击了击次button1 ,然后就会打开几个form1 的实例,
    如何捕捉其中的一个 啊??
    你可以设置一下,如果已经有一个实例了就把button1设置为不可用
    真是搞不懂你
    什么是捕捉其中的一个?你这句话让人不明白哦
      

  7.   

    如果主窗体是MDI父窗体的话:MdiParent属性,子窗体的)
    假设名称为frmParent。
        frmParent.IsMdiContainer=true;
    创建一个子窗体,假设子窗体name为frmChild
        frmChild.IsMdiChild=true;
        frmChild.text="子"
    主窗体中button1_click的代码:
    for(int i=0;i<this.MdiChildren.Length;i++) //(MdiChildren属性是子窗体的form[])
    {
    Form frmInstan=MdiChildren[i];
    if(frmInstan.Text=="子")
          frmInstan.Show();
    }
    frmChild frmChildInstan = new frmChild();
    frmParent.MdiParent = this;
    frmChildInstan .Show();
    ============================================================================
    如果不是MID:
    假设两个窗体:from1,from2(避免被多次调用的窗体);
                  from2.text="子"
    [from1中引用的命名空间]:
    using System.Runtime.InteropServices; //命名空间提供可用于访问 .NET 中的 COM 对象
    和本机 API 的类的集合。
    using System;//指针或句柄的平台特定类型[from1中引用成员函数]:
    [STAThread]
    [DllImport("User32",EntryPoint="FindWindow")]
    private static extern IntPtr FindWindow(string lpClassName,string lpWindowName);[DllImport("User32",EntryPoint="SetForegroundWindow")] private static extern bool SetForegroundWindow(IntPtr hWnd);[STAThread]
    [DllImport("User32",EntryPoint="FindWindowEx")] private static extern IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,string lpClassName,string lpWindowName);[from1 中button1_click 代码]:
    bool bHigherPriorityWindowfrom;
    IntPtr hWndLogin = FindWindow(null, "子");+"  "+IntPtr.Zero.ToString());
    if(hWndLogin != IntPtr.Zero)
    {
      bHigherPriorityWindowfrom = SetForegroundWindow(hWndLogin);//如果存在激活并显示
    }
    else
    {
      from2 from2Instan = new from2();
      from2Instan .Show();
    }
      

  8.   

    TO  回复人: quzw(quzw)如果(拥有的子窗口.数量 > 0)
      返回;             //已经有打开的窗口了,不做操作,直接返回.新的中文编程语言..呵..
      

  9.   

    那你需要判断 newfrm 是肤创建?follow 
    if(newfrm == null || !newfrm.IsCreate())
    {
           new form1();
    }
    else
    {
        newfrm.focu();
    }