我正在使用c#winforms(.NET 4,0),我想创建一个"智能"密码文本框类(或UserControl),它显示输入的字符一段时间,然后屏蔽该字符.我查看了这篇文章:使用"智能"密码char创建一个文本框,解决方案效果很好,但是在Form类中完成.我希望所有功能都在类或用户控件中,因此可以简单地将其拖放到表单上.
我的班级使用上面引用的解决方案:
using System;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
/// <summary>
/// TODO: Update summary.
/// </summary>
public class SmartTextBox : TextBox
{
public SmartTextBox()
{
InitializeComponent();
}
#region Component Designer generated code
private void InitializeComponent()
{
//
// SmartTextBox
//
this.TextChanged += new EventHandler(SmartTextBox_TextChanged);
}
#endregion
System.Threading.Timer timer = null;
void SmartTextBox_TextChanged(object sender, EventArgs e)
{
base.OnTextChanged(e);
if (timer == null)
{
timer = new System.Threading.Timer(new TimerCallback(Do), null, 1000, 1000);
}
SmartTextBox tb …
Run Code Online (Sandbox Code Playgroud)