[英]Show On Screen Key Board on mouse left button down on PasswordBox and should Hide when click outside the box
Platform: C# WPF 平台: C#WPF
Environment: Visual Studio 2013 环境: Visual Studio 2013
Question # 1 : I want to show third party on screen keyboard on mouse left button down on PasswordBox
control of C# WPF. 问题1 :我想在C#WPF的PasswordBox
控件的鼠标左键上显示屏幕键盘上的第三方。 I used the following code: 我使用了以下代码:
private void PasswordBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("D:\\CCOnScreenKeyboard.exe");
}
But it does not start on screen key board. 但它不会在屏幕键盘上启动。 Instead it triggers on MouseDoubleClick
and GotFocus
events. 相反,它会在MouseDoubleClick
和GotFocus
事件上触发。
Question # 2 : 问题#2 :
I want to Hide on screen keyboard when mouse click outside the PasswordBox
and Show again on mouse left button down inside box. 我想在PasswordBox
框外单击鼠标时在屏幕键盘上隐藏,然后在鼠标左键单击框内再次显示。
Question # 3 : 问题#3 :
I want to show keyboard on single click instead of mouse double click 我想在单击时显示键盘而不是鼠标双击
I belive the best way to do this will be through using the Focus
events, as you only want the keyboard when you're interacting with the PasswordBox
, and for it to go once you have stopped interacting. 我相信最好的方法是使用Focus
事件,因为你只需要在与PasswordBox
交互时使用键盘,并且一旦你停止了交互就去了。
private void PasswordBox_GotFocus(object sender, RoutedEventArgs e) =>
Process.Start("D:\\CCOnScreenKeyboard.exe");
private void PasswordBox_LostFocus(object sender, RoutedEventArgs e)
{
foreach (var process in Process.GetProcessesByName("CCOnScreenKeyboard"))
process.Kill();
}
You could handle the PreviewMouseLeftButtonDown
event for the parent window. 您可以处理父窗口的PreviewMouseLeftButtonDown
事件。 Something like this: 像这样的东西:
bool isVisible = false;
PreviewMouseLeftButtonDown += (ss, ee) =>
{
if (!passwordBox.IsMouseOver && isVisible)
{
System.Diagnostics.Process.GetProcessesByName("CCOnScreenKeyboard")?.FirstOrDefault()?.Kill();
}
else if (!isVisible)
{
System.Diagnostics.Process.Start("D:\\CCOnScreenKeyboard.exe");
isVisible = true;
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.