简体   繁体   English

如何使用SendKeys将值从一种形式传递到另一种形式

[英]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. 我有一个包含虚拟键盘的Mainform,并且想向其他表单输入文本。 My problem is when I click on the virtual keyboard which is on my Mainform, the second form becomes inactive. 我的问题是,当我单击Mainform上的虚拟键盘时,第二个窗体变得不活动。 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. 您可以使用以下代码激活Windows。 But i think what you want is in following link, 但我认为您想要的是以下链接,

http://www.codeproject.com/Articles/13596/Touchscreen-Keyboard-UserControl 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
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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