I have a windows form application that contains a textbox. I want to open the windows form exe from another application (c# application) and write in the textbox from my form application. I have the following code. I don’t see the text in my textbox .Why?
[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
static void Main(string[] args)
{
Process myProcess = Process.Start(
@"C:\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe");
SetForegroundWindow(myProcess.Handle);
if (myProcess.Responding)
{
Thread.Sleep(2000);
System.Windows.Forms.SendKeys.SendWait(
"This text was entered using the System.Windows.Forms.SendKeys method.");
System.Windows.Forms.SendKeys.SendWait(" method.");
//Thread.Sleep(2000);
}
else
{
myProcess.Kill();
}
You need to find the correct window in which you want to place the text. You can do this through
FindWindowandFindWindowExcombination. After that callSetFocuswith the handle of that window as parameter. And only after that callSendKeysto send text data to that window.Sample code would be something like this: