Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a text box for inputing password in winforms?

Tags:

c#

.net

winforms

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.

like image 626
pecker Avatar asked Mar 31 '10 19:03

pecker


People also ask

What kind of property can we use for a password in C#?

How to set the PasswordChar of the TextBox in C#? Here, the value of this property is of System. Char type and the character used to mask characters entered in a single-line TextBox. The value of this property is set to 0 (character value) if you do not want the control to mask characters as they are typed.

How do I set text to TextBox?

Step 1: Create a windows form. Step 2: Drag the TextBox control from the ToolBox and Drop it on the windows form. You can place TextBox anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the TextBox control to set the Text property of the TextBox.


2 Answers

The best way to solve your problem is to set the UseSystemPasswordChar property to true. 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 handling.

like image 69
AxelEckenberger Avatar answered Sep 27 '22 18:09

AxelEckenberger


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.");   }   
like image 21
z-boss Avatar answered Sep 27 '22 18:09

z-boss