在winform空密码字符 [英] Null Password Char in Winform

查看:251
本文介绍了在winform空密码字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本在C#中的windows窗体我有中分配一个空值问题的 PasswordChar 。我想要做的是,如果一个复选框被选中则 PasswordChar 即应否则显示的实际文本的 PasswordChar * 。这是我曾尝试

I have a textbox in a c# windows form i am having problems in assigning a null values to a PasswordChar. What i want to do is that if a checkbox is checked then the PasswordChar should be null i.e the actual text should be displayed else the PasswordChar should be *. This what i have tried

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (!checkBox1.Checked)
        {
            txtPassword.PasswordChar = '*';
        }
        else
        {
            txtPassword.PasswordChar = '';
        }
    }

但此行

     txtPassword.PasswordChar = ''; 

时,产生错误。我甚至试过

is generating an error. I have even tried

     txtPassword.PasswordChar = null;

但我仍然得到一个错误。

but i still get an error.

请帮我纠正我的code。

Please help me correct my code.

推荐答案

要重置 PassswordChar ,这样做 txtPassword.PasswordChar ='\\ 0' ;

为了方便您:

private void checkBox1_CheckedChanged(object sender, EventArgs e){
   txtPassword.PasswordChar = checkBox1.Checked ? '*' : '\0';
}

这篇关于在winform空密码字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆