【发布时间】:2023-03-13 18:35:01
【问题描述】:
我正在使用虚拟键盘做一个 WPF 应用程序。如图中提到的,有两个文本框 pseudo 和 password,我想使用虚拟键盘输入它们的值。
问题是如何知道光标是在第一个字段中还是在第二个字段中或外面。我尝试了isfocused,但没有给出结果。
那么我该怎么做呢?
public partial class Authentification : Window
{
public TextBox numero = new TextBox();
bool isPseudoFocused = false;
bool isPasswordFocused = false;
public Authentification()
{
InitializeComponent();
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
if (Keyboard.FocusedElement == pseudo)
MessageBox.Show("hhhh");
}
private void un_Click(object sender, RoutedEvent e)
{
if (isPseudoFocused) pseudo.Text += "1";
if (isPasswordFocused) password.Text += "1";
}
private void pseudo_FocusableChanged(Object sender, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show("pseudo");
isPseudoFocused = true;
isPasswordFocused = false;
}
private void password_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show("password");
isPseudoFocused = false;
isPasswordFocused = true;
}
}
【问题讨论】:
-
我认为您应该以某种方式指定要编写的文本框。