【发布时间】:2014-08-22 11:11:21
【问题描述】:
首先我想强调我正在寻找一个Windows DESKTOP WPF解决方案,所以请不要使用android。谢谢。
其次,我对 WPF 和为 Windows 平板电脑设计软件还很陌生,所以请多多包涵……请务必明确回答。
第三,目标软件将在 Windows 平板电脑(Win 8.0/8.1)上运行,并且正在使用 Visual Studio 2013 Pro(C#、桌面应用程序、WPF)进行开发。
好的,这是我的问题:
当用户触摸文本框时,我一直在使用文本框继承类来显示软键盘(类代码如下)。这部分实际上运作良好。 我的问题是软键盘可能会弹出我的实际控制。在 WinRT 中,这不会发生,因为操作系统似乎会向上滚动所述控件直到它变得可见,但对于 DESKTOP 应用程序,则不存在此类功能。
所以我的问题是:有人知道如何解决这个重叠问题吗?
我如何(在 Win 桌面应用程序中)复制正常的 WinRT 行为?
我应该使用其他 API 来调用软键盘吗?
“TouchTextbox”类的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace WPF_DT_Soft_Keyboard
{
class TouchTextbox : TextBox
{
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
protected override void OnGotFocus(System.Windows.RoutedEventArgs e)
{
base.OnGotFocus(e);
ShowSoftKeyboard();
}
protected override void OnLostFocus(System.Windows.RoutedEventArgs e)
{
base.OnLostFocus(e);
HideSoftKeyboard();
}
protected override void OnPreviewKeyUp(System.Windows.Input.KeyEventArgs e)
{
base.OnPreviewKeyUp(e);
if (e.Key == System.Windows.Input.Key.Enter) HideSoftKeyboard();
}
private void ShowSoftKeyboard()
{
System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
}
private void HideSoftKeyboard()
{
int iHandle = FindWindow("IPTIP_Main_Window", "");
if (iHandle > 0)
{
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
}
}
【问题讨论】:
-
启动后使用setwindowpos msdn.microsoft.com/en-us/library/ms633545%28VS.85%29.aspx
-
嗨凯文,我尝试了你的方法......首先我在调用 SetWindowPos 后从 GetLastError 得到一个 ERROR_ACCESS_DENIED。所以然后我以管理员身份运行我的 VS13,错误消失了,但软键盘窗口仍然没有移动......有什么想法吗?
-
你怎么称呼它?像这样? SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
-
SetWindowPos(iHandle, HWND_TOP, 500, 500, 0, 0, SWP_NOSIZE);
-
我刚刚尝试了您的确切调用“SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);"而且我没有收到错误(函数返回 1),但软键盘的位置仍然没有改变......
标签: c# .net wpf desktop-application