如何取消屏蔽密码文本框并将其屏蔽回密码?

发布于 2024-12-17 00:12:39 字数 125 浏览 0 评论 0原文

如何将设置为 : 的密码文本框

password_txtBox.PasswordChar ="*"

取消屏蔽(从复选框),然后再次屏蔽
不会丢失文本框中的字符串

How can password textbox that set to :

password_txtBox.PasswordChar ="*"

to be unmasked ( from checkbox ) and then mask again
without loosing the string inside the textbox

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

灯角 2024-12-24 00:12:39

只需将该属性设置为'\0'(这是默认值)即可不屏蔽字符。

来源: http://msdn.microsoft.com /en-us/library/system.windows.forms.textbox.passwordchar.aspx

注意:请注意“\0”与“0”不同。第一个是空字符,白色“0”是将显示为 0 的字符。

Just set the property to '\0' (which is the default value) to not mask characters.

Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.passwordchar.aspx

Note: notice that '\0' is different from '0'. The first one is the null character, white '0' is the character that will be displayed as 0.

小苏打饼 2024-12-24 00:12:39

对于winforms

private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e) {
   textBoxPassword.PasswordChar = checkBoxShowPassword.Checked ? '\0' : '*';
}

For winforms:

private void checkBoxShowPassword_CheckedChanged(object sender, EventArgs e) {
   textBoxPassword.PasswordChar = checkBoxShowPassword.Checked ? '\0' : '*';
}
家住魔仙堡 2024-12-24 00:12:39

如果您使用切换开关,那么

private void toggleSwitch1_Toggled(object sender, EventArgs e)
{
    if (toggleSwitch1.IsOn)
    {
        string a= textBox2.Text;
        textBox2.PasswordChar = '\0';
    }
    else
    {
        textBox2.PasswordChar = '*';
    }
}

此处 '\0' 将显示以纯文本形式提交的密码

If you are working with toggle switch then

private void toggleSwitch1_Toggled(object sender, EventArgs e)
{
    if (toggleSwitch1.IsOn)
    {
        string a= textBox2.Text;
        textBox2.PasswordChar = '\0';
    }
    else
    {
        textBox2.PasswordChar = '*';
    }
}

here '\0' will show to password filed to plain text

遗弃M 2024-12-24 00:12:39

txtPassword 是密码文本框,chkSeePassword 是显示密码复选框。现在向复选框的 CheckedChanged 事件添加一些代码

private void chkSeePassword_CheckedChanged(object sender, EventArgs e)
{
        txtPassword.UseSystemPasswordChar = !chkSeePassword.Checked;
}

txtPassword is the Password textbox, chkSeePassword is the Show password checkbox. Now add some code to the checkbox's CheckedChanged event

private void chkSeePassword_CheckedChanged(object sender, EventArgs e)
{
        txtPassword.UseSystemPasswordChar = !chkSeePassword.Checked;
}
疯了 2024-12-24 00:12:39

显示和隐藏密码的最简单方法之一是使用密码文本框中的单选按钮。

单选按钮的属性应该类似于:

this.radioBtn_ShowHidePassword.AutoCheck = false;    

然后必须手动处理单击活动,使其与“当前状态”相反。单击“事件

private void radioBtn_ShowHidePassword_Click(object sender, EventArgs e)
{
 radioBtn_ShowHidePassword.Checked = (! radioBtn_ShowHidePassword.Checked);
}

,最后是显示和隐藏密码的最简单方法

private void radioBtn_ShowHidePassword_CheckedChanged(object sender, EventArgs e)
{
   txtBoxPassword.PasswordChar = radioBtn_ShowHidePassword.Checked ? '\0' : '*';
   // here we can even include the code for changing the default picture of button to two different
   //representation like closed eye and opened eye which resembles Windows login
}

One of the easiest method to show and hide password is by using radio button inside password text box

The properties of radio button should be like:

this.radioBtn_ShowHidePassword.AutoCheck = false;    

then the clicking activity has to be taken care manually just making it to be reverse of present state in its "Click" event

private void radioBtn_ShowHidePassword_Click(object sender, EventArgs e)
{
 radioBtn_ShowHidePassword.Checked = (! radioBtn_ShowHidePassword.Checked);
}

then finally the easiest way of show and hide password

private void radioBtn_ShowHidePassword_CheckedChanged(object sender, EventArgs e)
{
   txtBoxPassword.PasswordChar = radioBtn_ShowHidePassword.Checked ? '\0' : '*';
   // here we can even include the code for changing the default picture of button to two different
   //representation like closed eye and opened eye which resembles Windows login
}
断肠人 2024-12-24 00:12:39

我这样做是为了简单地显示密码
(我在编码方面还很陌生,所以如果这是一个不好的做法,欢迎反馈)

 private void buttonShowPassword_MouseDown(object sender, MouseEventArgs e)
    {
        TextBoxPassword.Properties.PasswordChar =(char)0;
    }

    private void buttonShowPassword_MouseUp(object sender, MouseEventArgs e)
    {
        TextBoxPassword.Properties.PasswordChar = '*';
    }

I did this to briefly show the password
(I am pretty new at coding so feedback welcome if this is a bad practise)

 private void buttonShowPassword_MouseDown(object sender, MouseEventArgs e)
    {
        TextBoxPassword.Properties.PasswordChar =(char)0;
    }

    private void buttonShowPassword_MouseUp(object sender, MouseEventArgs e)
    {
        TextBoxPassword.Properties.PasswordChar = '*';
    }
↘人皮目录ツ 2024-12-24 00:12:39
if(TokenTextBox.PasswordChar == (char)0)
{
   TokenTextBox.PasswordChar = '•';
}
else
{
   TokenTextBox.PasswordChar = (char)0;
}
if(TokenTextBox.PasswordChar == (char)0)
{
   TokenTextBox.PasswordChar = '•';
}
else
{
   TokenTextBox.PasswordChar = (char)0;
}
甜味拾荒者 2024-12-24 00:12:39

用这个

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        textBox2.PasswordChar = default(char);
    }

use this one

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        textBox2.PasswordChar = default(char);
    }
冬天的雪花 2024-12-24 00:12:39

VB.Net 版本是

Private Sub checkBoxShowPassword_CheckedChanged(sender As Object, e As System.EventArgs) Handles checkBoxShowPassword.CheckedChanged
    textBoxPassword.PasswordChar = If(checkBoxShowPassword.Checked, ControlChars.NullChar, "*"C)
End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked Then
        Me.txt_password.PasswordChar = "*"c
    Else
        Me.txt_password.PasswordChar = ControlChars.NullChar
    End If
End Sub

The VB.Net version is

Private Sub checkBoxShowPassword_CheckedChanged(sender As Object, e As System.EventArgs) Handles checkBoxShowPassword.CheckedChanged
    textBoxPassword.PasswordChar = If(checkBoxShowPassword.Checked, ControlChars.NullChar, "*"C)
End Sub

or

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked Then
        Me.txt_password.PasswordChar = "*"c
    Else
        Me.txt_password.PasswordChar = ControlChars.NullChar
    End If
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文