winform程序1,程序2:程序2有个主窗体A程序1怎么获得程序1的主窗体A ???

解决方案 »

  1.   

    从进程下手吧。程序2运行了就有个进程。程序2.ext
      

  2.   

    搞错了。是程序2winform程序1,程序2:程序2有个主窗体A 程序1怎么获得程序2的主窗体A ???
      

  3.   

    两个窗体通信还是两个exe通信,如果两个exe,那么就要从进程通信入手了。三思我的博客 程序员日记 http://www.ideaext.com 欢迎交流
      

  4.   

    在程序1通过反射程序2的DLL文件,创建窗体A。
      

  5.   

    private void CreateForm(string strName)
    {
    this.Cursor = Cursors.WaitCursor;string path=AssemblyName;
    string name=strName; Form fm=(Form)Assembly.Load(path).CreateInstance(name);
    fm.MdiParent=this.ParentForm;
    fm.Show();
    fm.Dock=DockStyle.Fill;
    this.Cursor = Cursors.Default;
    }
      

  6.   


    [DllImport("User32.dll", EntryPoint = "FindWindow")]
    private static extern int FindWindow(string lpClassName, string lpWindowName);private void button1_Click(object sender, EventArgs e)
    {
           int WINDOW_HANDLER = FindWindow(null, @"主窗体A");
           if (WINDOW_HANDLER == 0)
           {
               //不存在
                 ......
           }
           else
           {
               //存在
                 ......
           }
    }
      

  7.   


    int SC_MAXIMIZE = 0xf030;
            int WM_SYSCOMMAND = 0x0112;        [DllImport("User32.dll", EntryPoint = "FindWindow")]
            private static extern int FindWindow(string lpClassName, string lpWindowName);        [DllImport("User32.dll", EntryPoint = "SendMessage")]
            private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);        private void button1_Click(object sender, EventArgs e)
            {
                int WINDOW_HANDLER = FindWindow(null, @"应用程序1");
                if (WINDOW_HANDLER == 0)
                {            }
                else
                {
                    SendMessage((System.IntPtr)WINDOW_HANDLER, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
                }
            }
      

  8.   

     int WINDOW_HANDLER = FindWindow(null, @"这是什么?是程序2的名字?");
      

  9.   

    在程序1里写 this.SendToBack();