Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用SendKeys将值从一个窗体传递到另一个窗体_C#_Winforms - Fatal编程技术网

C# 如何使用SendKeys将值从一个窗体传递到另一个窗体

C# 如何使用SendKeys将值从一个窗体传递到另一个窗体,c#,winforms,C#,Winforms,我有个问题。我有一个主窗体,它包含一个虚拟键盘,我想在另一个窗体中输入一个文本。我的问题是,当我点击主窗体上的虚拟键盘时,第二个窗体变为非活动状态。因此,当我键入时,不会出现其他形式的字母 有没有办法激活这两种形式?或者有没有其他方法来解决这个问题 谢谢。您可以使用以下代码激活windows。但我想你想要的是下面的链接 public class Win32 : IWin32 { //Import the FindWindow API to find our window [Dl

我有个问题。我有一个主窗体,它包含一个虚拟键盘,我想在另一个窗体中输入一个文本。我的问题是,当我点击主窗体上的虚拟键盘时,第二个窗体变为非活动状态。因此,当我键入时,不会出现其他形式的字母

有没有办法激活这两种形式?或者有没有其他方法来解决这个问题


谢谢。

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

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
        }
    }
}