using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace PassWordManager
{
///
/// 密码控件
///
public partial class PassWordText : UserControl
{
///
///
///
public PassWordText()
{
InitializeComponent();
}
private int isProUse = 0;
private string m_PassWord = "";
///
/// 密码
///
[Description("密码")]
public string PassWord
{
get { return m_PassWord; }
set
{
m_PassWord = value;
label1.Text = "";
for (int i = 0; i < m_PassWord.Length; i++)
{
label1.Text += "*";
}
}
}
private void label1_Click(object sender, EventArgs e)
{
EnterEditText();
}
private void textBox1_Leave(object sender, EventArgs e)
{
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
isProUse = 1;
textBox1.Visible = false;
}
else if (e.KeyCode == Keys.Enter)
{
isProUse = 1;
m_PassWord = textBox1.Text;
label1.Text = "";
for (int i = 0; i < m_PassWord.Length; i++)
{
label1.Text += "*";
}
textBox1.Visible = false;
}
}
private void PassWordText_Click(object sender, EventArgs e)
{
EnterEditText();
}
private void PassWordText_Load(object sender, EventArgs e)
{
textBox1.Width = Width;
textBox1.Left = 0;
textBox1.Top = 0;
Height = textBox1.Height;
label1.Top = (Height - label1.Height) / 2;
}
private void EnterEditText() //进入编辑框
{
textBox1.Clear();
textBox1.Visible = true;
try
{
textBox1.Focus();
}
catch { }
}
private void LeaveEditText() //离开编辑框
{
if (textBox1.Text == "")
{
}
else
{
m_PassWord = textBox1.Text;
label1.Text = "";
for (int i = 0; i < m_PassWord.Length; i++)
{
label1.Text += "*";
}
}
textBox1.Visible = false;
}
private void PassWordText_Resize(object sender, EventArgs e)
{
textBox1.Width = Width;
textBox1.Left = 0;
textBox1.Top = 0;
Height = textBox1.Height;
label1.Top = (Height - label1.Height) / 2;
}
private void PassWordText_Leave(object sender, EventArgs e)
{
if (isProUse == 0)
{
LeaveEditText();
}
else
{
isProUse = 0;
}
}
}
}