I am using Visual Studio 2015 and im looking for tips for my idea. So i have textbox with placeholder text "Password" and when i focused on it, its changing forecolor and starting using UseSystemPasswordChar = true. I have a class for placeholder text:
class PlaceHolderTextBox
{
public void SetPlaceHolder(Control control, string PlaceHolderText)
{
control.Text = PlaceHolderText;
control.GotFocus += delegate (object sender, EventArgs args) {
if (control.Text == PlaceHolderText)
{
control.Text = "";
control.ForeColor = Color.Black;
}
};
control.LostFocus += delegate (object sender, EventArgs args) {
if (control.Text.Length == 0)
{
control.Text = PlaceHolderText;
control.ForeColor = SystemColors.InactiveCaption;
}
};
}
}
And i need a CheckBox "Show password" which allows if checked show the password. So here is my login code:
private void Login_Load(object sender, EventArgs e)
{
PlaceHolderTextBox tb = new PlaceHolderTextBox();
tb.SetPlaceHolder(TbUsername, "Username");
tb.SetPlaceHolder(TbPassword, "Password");
}
private void LlSignUp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
SignUp reg = new SignUp();
reg.Show();
}
private void LlClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Application.Exit();
}
private void BtLogin_Click(object sender, EventArgs e)
{
this.Hide();
Main main = new Main();
main.Show();
}
private void CbShowPassword_CheckedChanged(object sender, EventArgs e)
{
if (CbShowPassword.Checked)
TbPassword.UseSystemPasswordChar = false;
else
TbPassword.UseSystemPasswordChar = true;
}
private void TbPassword_Enter(object sender, EventArgs e)
{
TbPassword.UseSystemPasswordChar = true;
}
private void TbPassword_Leave(object sender, EventArgs e)
{
TbPassword.UseSystemPasswordChar = false;
}
The problem is that i cant use these 2 solutions together and dont know how to solve it
Aucun commentaire:
Enregistrer un commentaire