tags:

views:

120

answers:

3

how to set a text box for inputing password in winforms? Also I want to show "Capslock is ON" popup if capslock is on.

I want something like

<input type="password" /> in HTML.

A: 

Just set the TextBox.PasswordChar property to '*'.

Reed Copsey
+1  A: 

The best way to solve your problem is to set the UseSystemPasswordChar property to ture. Then the caps lock message is shown when the user enters the field and the Caps-Lock is on (at least for Vista and Windows 7).

Another alternative is to set the PasswordChar property to a character value (* for example). This also triggers the automatic Caps-Lock hanlding.

Obalix
+2  A: 

To set a text box for password input:

textBox1.PasswordChar = '*';

you can also change this property in design time by editing properties of the text box.

To show if "Capslock is ON":

using System;  
using System.Windows.Forms;  
//...
if (Control.IsKeyLocked(Keys.CapsLock)) {  
    MessageBox.Show("The Caps Lock key is ON.");  
}  
z-boss
Instead of messagebox isn't it possible to get that nice yellow colored popup. which we generally get in system tray when our antivirus is out of date or firewall is tuned off. But I want that to be displayed for text box. It is shown for Google Talk.
pecker
You can set a pop-up for control, see example here: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.popup.aspx
z-boss
If the `PasswordChar` or the `UseSystemPasswordChar` is used - at least on Windows 7 and Vista - the Caps-Lock is handled automatically if the field receives the focus.
Obalix