我有问题。我有这个Mainform,它包含一个虚拟键盘,并希望将文本输入到我的其他表单。我的问题是,当我点击我的Mainform上的虚拟键盘时,第二个表单变为非活动状态。因此,当我输入时,不会以其他形式出现字母。
有没有办法让这两种形式活跃起来?或者还有其他方法可以解决这个问题吗?
谢谢。
答案 0 :(得分: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
}
}
}