0

我有个问题。我有这个包含虚拟键盘的 Mainform,并且想在我的其他表单中输入文本。我的问题是,当我单击主窗体上的虚拟键盘时,第二个窗体变为非活动状态。因此,当我键入时,没有字母会以其他形式出现。

有没有办法让这两种形式活跃?或者有没有其他方法可以解决这个问题?

谢谢你。

4

1 回答 1

0

您可以使用以下代码激活 Windows。但我认为你想要的是下面的链接,

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
        }
    }
}
于 2013-09-11T09:43:30.200 回答