Winform: a problem caused by a login form series (3): Password text box input restrictions

Source: Internet
Author: User
Tags api manual

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.