怎么在一个程序中获取另外一个窗体的textbox的值,求解

解决方案 »

  1.   

    [DllImport("user32.dll", EntryPoint = "FindWindow")]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
            public static extern IntPtr FindWindowEx(IntPtr hWnd1, IntPtr hWnd2, string lpsz1, string lpsz2);
            [DllImport("User32 ")]
            public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
            public const int WM_GETTEXT = 0xD;
            private void button1_Click(object sender, EventArgs e)
            {
                if (pcalc == null || pcalc.HasExited) return;
                IntPtr hEdit = FindWindowEx(pcalc.MainWindowHandle, IntPtr.Zero, "Edit", null);
                string w = " ";
                IntPtr ptr = Marshal.StringToHGlobalAnsi(w);
                if (SendMessage(hEdit, WM_GETTEXT, 100, ptr))
                {
                    MessageBox.Show(Marshal.PtrToStringAnsi(ptr));
                }
            }
      

  2.   

    没看懂,我的程序是这样的,进入一个窗体修改密码,需要前一个窗体的textbox的值,怎么获取,求解
      

  3.   

    bs cs? BS传参数。CS我都用共通类里面的属性传值
      

  4.   

    页面之间传值呗。方法有很多啊。1. static public property
    2. owner public property
    ...
      

  5.   


    为你的修改密码的窗体设计property,然后程序先给它赋值(前一个窗体将自己的值设置给new出来的这个窗体实力的属性)。
      

  6.   

    以下方法不适用过托管程序(.NET,Java)
    API 详细用法请google or baiduSPY++:http://www.newhua.com/soft/1669.htm
    //首先查找窗口句柄
    this.mainWnd = FindWindow(null, "Citrix Secure Access");
    用SPY++ 找到你要填写textbox的句柄
    //通过SPY++获取相就textbox的名柄
    IntPtr dlgItem = GetDlgItem(this.mainWnd, 0x3fe);
    //通过发送消息的方式填写textbox内容
    SendMessage(hWnd, 12, IntPtr.Zero, "NCS@Cag");
    用到的API
    //查找主窗体API
    [DllImport("user32.dll", SetLastError=true)]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    //查找主窗体里的控件
      [DllImport("user32.dll ")]
      public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
    //发送消息
    [DllImport("User32.dll")]
      public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
      

  7.   

    你可以新添加一个类,定义一个string的变量,把前一个窗体的textBox的值传过去,在第二个窗体上调用就好了,比如第一个页面上的textBox的name 是txtPwd
    //添加一个类Helper,定义一个公共的静态的变量Pwd接收第一个窗体的值,静态的可以直接用类名打点来访问成员变量的,不必实例化
    public static string pwd="";在它的TextChanged事件里写
    Helper.pwd=txtPwd.Text.Trim();//将txtPwd里的值传给定义的Helper类里面的变量Pwd在第二个窗体里调用就可以//比如第二个的textBox的name是txtPwd1则:txtPwd1.Text=Helper.pwd;
    就可以了
      

  8.   

    TextChanged事件实在第一个窗体的textBox的事件里
      

  9.   

    http://developer.51cto.com/art/201006/205587.htm
      

  10.   

    窗体之间传值:session,ViewState,Url都可以的。