简体   繁体   中英

How to Pass Value from one Form to another using SendKeys

I have a problem. I have this Mainform which contains a virtual keyboard and would like to input a text to my other form. My problem is when I click on the virtual keyboard which is on my Mainform, the second form becomes inactive. So when I type no letters will appear in the other form.

Is there a way to make these two forms active? Or are there any other methods to solve this problem?

Thank you.

you can activate windows using following code. But i think what you want is in following link,

http://www.codeproject.com/Articles/13596/Touchscreen-Keyboard-UserControl

public class Win32 : IWin32
{
    //Import the FindWindow API to find our window
    [DllImport("User32.dll", EntryPoint = "FindWindow")]
    private static extern IntPtr FindWindowNative(string className, string windowName);

    //Import the SetForeground API to activate it
    [DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
    private static extern IntPtr SetForegroundWindowNative(IntPtr hWnd);

    public IntPtr FindWindow(string className, string windowName)
    {
        return FindWindowNative(className, windowName);
    }

    public IntPtr SetForegroundWindow(IntPtr hWnd)
    {
        return SetForegroundWindowNative(hWnd);
    }
}

public class SomeClass
{
    public void Activate(string title)
    {
        //Find the window, using the Window Title
        IntPtr hWnd = win32.FindWindow(null, title);
        if (hWnd.ToInt32() > 0) //If found
        {
            win32.SetForegroundWindow(hWnd); //Activate it
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM