2009-06-18 63 views
1

如何通過使用WPF的虛擬鍵盤使用密碼箱控件?使用文本框控件,將插入符號移動到下一個文本位置非常簡單;密碼框不是這樣,它不會暴露插入位置。wpf passwordbox caret

我應該只是推導出我自己的?看起來像軟醬。

回答

1

你可以嘗試這樣的事情來設置在PasswordBox選擇:

private void SetSelection(PasswordBox passwordBox, int start, int length) { 
    passwordBox.GetType().GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic) 
         .Invoke(passwordBox, new object[] { start, length }); 
} 

之後,調用它來設置光標位置:

// set the cursor position to 2... or length of the password 
SetSelection(passwordBox1, 2, 0); 

// focus the control to update the selection 
passwordBox1.Focus(); 

提供了以上回答通過Andrew Jackson,它工作正常。

+0

你會如何確定當前的脫字號位置? – 2014-05-20 07:16:18