The restrictions on the input of password texts are mainly concentrated on the following two problems:
I. password length input restrictions
This is the same as the user name input limit. You can directly change the txtpassword maxlength attribute. Here we set it to 16
Ii. display of passwords
Directly change the passwordchar attribute of txtpassword, which is generally set "*".
3. The Password text box cannot be pasted, copied, or blocked by right-clicking
This is a difficult issue. We use the method to write a new class that inherits Textbox, and rewrite its wndproc method to process it by listening to the Message ID.
Specific steps:
Create a new class named textbox. cs. The Code is as follows:
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Windows. forms;
Namespace frmlogin
{
Public class textboxex: system. Windows. Forms. textbox
{
//
// The default constructor
//
Protected override void wndproc (ref message m)
{
If (M. MSG! = 0x007b & M. MSG! = 0x0301 & M. MSG! = 0x0302)
{
Base. wndproc (ref m );
}
}
}
}
0x007b: Right-click the Message ID
0x0301: Copy (including Ctrl + C) The Message ID (in fact, this judgment is not required, because the passwordchar attribute of textbox has actually blocked the copy function)
0x0302: paste (including Ctrl + V) Message ID
For more message IDs, refer to the http://liuhao-27.blog.163.com/blog/static/115851126200941425617778/
Or check the API manual.
Of course, our work is not over yet. We need to reference txtpassword in login. Designer. CS to this new object,
This.txt Password = new system. Windows. Forms. Textbox ();
Changed:
This.txt Password = new frmlogin. textboxex ();