Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF PasswordBox: How do I warn a user that Caps Lock is enabled?

Does anyone know how to implement the standard bubble message that warns users whenever Caps Lock is enabled and a password control has focus? Is this built into the .NET framework, or do I need to write my own class to do this?

like image 235
Rob Sobers Avatar asked Nov 26 '08 15:11

Rob Sobers


3 Answers

This is an old question, and already answered, but I came across this same problem and I first started with Keyboard.IsKeyToggled(Key.CapsLock) but that returned false if Caps Lock was set prior to the application running. So I found another solution that works perfectly.

Console.CapsLock //is boolean and returns true if CapsLock is on

Absolutely brilliant and simple (it's in the mscorlib dll so you don't have to worry about unneeded dependencies either)

like image 123
Jose Avatar answered Oct 24 '22 15:10

Jose


You could add a handler function to the PasswordChanged event handler and test for the value of the CapsLock key in that function. If found to be on, you could pop-up a message from there.

like image 39
xan Avatar answered Oct 24 '22 16:10

xan


If you use a MaskedTextBox and specify a passwordChar the .NET framework will automatically do this for you

like image 31
Jaime Garcia Avatar answered Oct 24 '22 15:10

Jaime Garcia