11 个解决方案
#2
FindWidow找到句柄
获取
SendMessage(WM_GETTEXT)
设置
SendMessage(WM_SETTEXT)
获取
SendMessage(WM_GETTEXT)
设置
SendMessage(WM_SETTEXT)
#3
#region 获取另一系统文本框值
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindEx")]
public static extern IntPtr FindEx(IntPtr hwnd, IntPtr hwndChild, string lpClassName, string lpWindowName);
//[DllImport("user32.dll", EntryPoint = "GetWindowText")]
//public static extern int GetWindowText(int hwnd, string lpString, int cch);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
#endregion
private void button1_Click(object sender, EventArgs e)
{
IntPtr maindHwnd = FindWindow(null, "Form1"); //获得句柄
int i = 0;
if (maindHwnd != IntPtr.Zero)
{
MessageBox.Show("找到了窗体!");
//找到窗体后这里如何去获取找到的这个窗体上的文本框的值???????
//控件id
int controlId = 0x000003F4;
//获取子窗口句柄
IntPtr EdithWnd = GetDlgItem(maindHwnd, controlId);
SendMessage(EdithWnd, i, (IntPtr)0, string.Format("当前时间是:{0}", DateTime.Now)); //赋值没问题,表示句柄正确
StringBuilder stringBuilder = new StringBuilder(512);
GetWindowText(EdithWnd, stringBuilder, stringBuilder.Capacity);
MessageBox.Show(string.Format("取到的值是:{0}", stringBuilder.ToString()));//取值一直是空字符串
}
else
{
MessageBox.Show("没有找到窗口");
}
}
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindEx")]
public static extern IntPtr FindEx(IntPtr hwnd, IntPtr hwndChild, string lpClassName, string lpWindowName);
//[DllImport("user32.dll", EntryPoint = "GetWindowText")]
//public static extern int GetWindowText(int hwnd, string lpString, int cch);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
#endregion
private void button1_Click(object sender, EventArgs e)
{
IntPtr maindHwnd = FindWindow(null, "Form1"); //获得句柄
int i = 0;
if (maindHwnd != IntPtr.Zero)
{
MessageBox.Show("找到了窗体!");
//找到窗体后这里如何去获取找到的这个窗体上的文本框的值???????
//控件id
int controlId = 0x000003F4;
//获取子窗口句柄
IntPtr EdithWnd = GetDlgItem(maindHwnd, controlId);
SendMessage(EdithWnd, i, (IntPtr)0, string.Format("当前时间是:{0}", DateTime.Now)); //赋值没问题,表示句柄正确
StringBuilder stringBuilder = new StringBuilder(512);
GetWindowText(EdithWnd, stringBuilder, stringBuilder.Capacity);
MessageBox.Show(string.Format("取到的值是:{0}", stringBuilder.ToString()));//取值一直是空字符串
}
else
{
MessageBox.Show("没有找到窗口");
}
}
#4
最笨的方法是循环查找:
当然还是可以有其他方法:
http://social.microsoft.com/Forums/nl-NL/3ca0b2d4-2a0c-4a97-ba83-5b3585aa274a/c?forum=2212
foreach (Form f in Application.OpenForms)
{
if (!(f is Form1)) continue;
foreach (Control c in (f as Form1).Controls)
{
if (!(c.Name.Equals("textbox1", StringComparison.CurrentCultureIgnoreCase))) continue;
string s = (c as TextBox).Text;
}
}
当然还是可以有其他方法:
http://social.microsoft.com/Forums/nl-NL/3ca0b2d4-2a0c-4a97-ba83-5b3585aa274a/c?forum=2212
#5
通过控件ID是能过找到自己想要的控件(比如说文本框)
但是每当你要获取值的系统重启以后,这个控件ID就不一样了,
请问该如何动态获取这个控件ID??
但是每当你要获取值的系统重启以后,这个控件ID就不一样了,
请问该如何动态获取这个控件ID??
#6
Form 1 f1;
f1=(Form)this.Owner;
label1.Tex=f1.textbox.Text;
f1=(Form)this.Owner;
label1.Tex=f1.textbox.Text;
#7
遍历找到窗体的所有的文本框然后来找吧
#8
#9
这个系统界面的程序上写上修改文本框的值的方法,再对this的窗体创建对象 调用方法 可以吗
#10
如果是我我会写一个静态类来保存这个信息
#11
这个使用windows API比较保险。
http://download.csdn.net/detail/mjp1234airen4385/1550580
看看这有有效果没
http://download.csdn.net/detail/mjp1234airen4385/1550580
看看这有有效果没
#1
使用SendMessage
http://www.cnblogs.com/wf5360308/articles/1426900.html
http://www.cnblogs.com/wf5360308/articles/1426900.html
#2
FindWidow找到句柄
获取
SendMessage(WM_GETTEXT)
设置
SendMessage(WM_SETTEXT)
获取
SendMessage(WM_GETTEXT)
设置
SendMessage(WM_SETTEXT)
#3
#region 获取另一系统文本框值
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindEx")]
public static extern IntPtr FindEx(IntPtr hwnd, IntPtr hwndChild, string lpClassName, string lpWindowName);
//[DllImport("user32.dll", EntryPoint = "GetWindowText")]
//public static extern int GetWindowText(int hwnd, string lpString, int cch);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
#endregion
private void button1_Click(object sender, EventArgs e)
{
IntPtr maindHwnd = FindWindow(null, "Form1"); //获得句柄
int i = 0;
if (maindHwnd != IntPtr.Zero)
{
MessageBox.Show("找到了窗体!");
//找到窗体后这里如何去获取找到的这个窗体上的文本框的值???????
//控件id
int controlId = 0x000003F4;
//获取子窗口句柄
IntPtr EdithWnd = GetDlgItem(maindHwnd, controlId);
SendMessage(EdithWnd, i, (IntPtr)0, string.Format("当前时间是:{0}", DateTime.Now)); //赋值没问题,表示句柄正确
StringBuilder stringBuilder = new StringBuilder(512);
GetWindowText(EdithWnd, stringBuilder, stringBuilder.Capacity);
MessageBox.Show(string.Format("取到的值是:{0}", stringBuilder.ToString()));//取值一直是空字符串
}
else
{
MessageBox.Show("没有找到窗口");
}
}
[DllImport("User32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindEx")]
public static extern IntPtr FindEx(IntPtr hwnd, IntPtr hwndChild, string lpClassName, string lpWindowName);
//[DllImport("user32.dll", EntryPoint = "GetWindowText")]
//public static extern int GetWindowText(int hwnd, string lpString, int cch);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("user32.dll ", EntryPoint = "GetDlgItem")]
public static extern IntPtr GetDlgItem(IntPtr hParent, int nIDParentItem);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
#endregion
private void button1_Click(object sender, EventArgs e)
{
IntPtr maindHwnd = FindWindow(null, "Form1"); //获得句柄
int i = 0;
if (maindHwnd != IntPtr.Zero)
{
MessageBox.Show("找到了窗体!");
//找到窗体后这里如何去获取找到的这个窗体上的文本框的值???????
//控件id
int controlId = 0x000003F4;
//获取子窗口句柄
IntPtr EdithWnd = GetDlgItem(maindHwnd, controlId);
SendMessage(EdithWnd, i, (IntPtr)0, string.Format("当前时间是:{0}", DateTime.Now)); //赋值没问题,表示句柄正确
StringBuilder stringBuilder = new StringBuilder(512);
GetWindowText(EdithWnd, stringBuilder, stringBuilder.Capacity);
MessageBox.Show(string.Format("取到的值是:{0}", stringBuilder.ToString()));//取值一直是空字符串
}
else
{
MessageBox.Show("没有找到窗口");
}
}
#4
最笨的方法是循环查找:
当然还是可以有其他方法:
http://social.microsoft.com/Forums/nl-NL/3ca0b2d4-2a0c-4a97-ba83-5b3585aa274a/c?forum=2212
foreach (Form f in Application.OpenForms)
{
if (!(f is Form1)) continue;
foreach (Control c in (f as Form1).Controls)
{
if (!(c.Name.Equals("textbox1", StringComparison.CurrentCultureIgnoreCase))) continue;
string s = (c as TextBox).Text;
}
}
当然还是可以有其他方法:
http://social.microsoft.com/Forums/nl-NL/3ca0b2d4-2a0c-4a97-ba83-5b3585aa274a/c?forum=2212
#5
通过控件ID是能过找到自己想要的控件(比如说文本框)
但是每当你要获取值的系统重启以后,这个控件ID就不一样了,
请问该如何动态获取这个控件ID??
但是每当你要获取值的系统重启以后,这个控件ID就不一样了,
请问该如何动态获取这个控件ID??
#6
Form 1 f1;
f1=(Form)this.Owner;
label1.Tex=f1.textbox.Text;
f1=(Form)this.Owner;
label1.Tex=f1.textbox.Text;
#7
遍历找到窗体的所有的文本框然后来找吧
#8
#9
这个系统界面的程序上写上修改文本框的值的方法,再对this的窗体创建对象 调用方法 可以吗
#10
如果是我我会写一个静态类来保存这个信息
#11
这个使用windows API比较保险。
http://download.csdn.net/detail/mjp1234airen4385/1550580
看看这有有效果没
http://download.csdn.net/detail/mjp1234airen4385/1550580
看看这有有效果没