我该如何更改PasswordBox?

时间:2014-03-10 10:31:02

标签: c# vb.net

请问如何在c#中将密码箱的星号更改为char(我将使用复选框来显示或隐藏密码值) 当复选框被取消时,密码框会变为像文本框一样保持值

3 个答案:

答案 0 :(得分:0)

要实现此目的,您必须屏蔽密码字符。

请参考。

how can i unmask c# password textbox and mask it back to password

答案 1 :(得分:0)

简介

目前尚不清楚你想要什么,或者你在做什么,VB或C#。但据我所知,为了您的安慰,我已经写了两篇文章。

代码和示例

在C#

指定PasswordChar

TextBox2.PasswordChar = "*";

OR

TextBox2.PasswordChar = "☻";

删除PasswordChar

TextBox2.PasswordChar = "";

在VB.net中:

指定PasswordChar

TextBox2.PasswordChar = "*"

OR

TextBox2.PasswordChar = "☻"

删除PasswordChar

TextBox2.PasswordChar = ""

解释

您可以在PasswordChar textbox属性之前的双引号中指定您想要的任何密码字符。要删除PasswordChar,我们上面谈到的双引号中应该没有任何值。

我希望它清晰且完美无缺!

答案 2 :(得分:0)

使用文本框并更改其属性yourTextBox.UseSystemPasswordChar - 如果要查看文本,请将其设置为false。如果您想使用复选框来控制它,您可以使用以下内容:

Private Sub yourCheckbox_CheckedChanged(sender As Object, e As EventArgs) Handles yourCheckbox.CheckedChanged

        If (yourCheckbox.Checked = true) then

            yourTextBox.UseSystemPasswordChar = true

        Else

            yourTextBox.UseSystemPasswordChar = false

        End If

 End Sub

这是VB.Net,但是如果您正在寻找C#,相应的代码应该很容易推断。

相关问题