如果选中复选框,如何隐藏和显示文本 vb.net

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33996346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:36:09  来源:igfitidea点击:

how to hide and show text if checkbox is checked vb.net

vb.netcheckbox

提问by Micah

So far my code is like this and they only enable and disable the Textbox.

到目前为止,我的代码是这样的,它们只启用和禁用文本框。

Private Sub CheckBox17_CheckedChanged(ByVal sender As System.Object, 
ByVal e As System.EventArgs) Handles CheckBox17.CheckedChanged

        If CheckBox17.Checked = True Then

        TextBox1.Enabled = False

    ElseIf CheckBox17.Checked = False Then

        TextBox1.Enabled = True
    End If
End Sub

I need some codes that hide the text when the checkbox is checked and show it when checked.

我需要一些代码来在复选框被选中时隐藏文本并在选中时显示它。

回答by Sascha

When the checkbox is checked copy the textbox contents to a string variable and set the textbox text property to an empty string (consideder setting textbox enabled to false). If the check is checked assign the string variable to the textbox text property again.

选中复选框后,将文本框内容复制到字符串变量并将文本框文本属性设置为空字符串(考虑将启用的文本框设置为 false)。如果选中该检查,则再次将字符串变量分配给文本框文本属性。

回答by betrice mpalanzi

a cording to question i this this example help this example show How to Hide and Show the Password Using a CheckBox

一个问题我这个例子帮助这个例子展示如何使用复选框隐藏和显示密码

i create a new Windows Form Application. After that, do the Form just like this.

我创建了一个新的 Windows 窗体应用程序。之后,像这样做表格。

enter image description here

在此处输入图片说明

Double click the checkbox and do this following code in the method. This method will set the password into bullets to hide it, or set it into letters to know the password that you have input exactly according to your desire.

双击复选框并在方法中执行以下代码。此方法将密码设置为项目符号以隐藏它,或者将其设置为字母以准确地根据您的需要知道您输入的密码。

'CHECKING IF THE CHECKBOX WAS CHECKED OR NOT.

'检查复选框是否被选中。

If CheckBox1.CheckState = CheckState.Checked Then'IF TRUE, IT SHOW THE TEXT txtpass.UseSystemPasswordChar = False Else

If CheckBox1.CheckState = CheckState.Checked Then'如果为真,则显示文本 txtpass.UseSystemPasswordChar = False Else

'IF FALSE, IT WILL HIDE THE TEXT AND IT WILL TURN IT INTIO BULLETS.

'如果为假,它将隐藏文本并将其变成子弹。

txtpass.UseSystemPasswordChar = True End If

txtpass.UseSystemPasswordChar = True End If

Go back to the design views, double click the form and do this following code in the Form_Load.

返回设计视图,双击窗体并在 Form_Load 中执行以下代码。

'HIDE THE TEXT OF THE TXTPASS ON THE FIRST LOAD

'在第一次加载时隐藏 TXTPASS 的文本

txtpass.UseSystemPasswordChar = True

txtpass.UseSystemPasswordChar = True

These are the full codes that you have made.

这些是您制作的完整代码。

Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

Public Class Form1 Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

'CHECKING IF THE CHECKBOX WAS CHECKED OR NOT.

'检查复选框是否被选中。

If CheckBox1.CheckState = CheckState.Checked Then

If CheckBox1.CheckState = CheckState.Checked Then

'IF TRUE, IT SHOWS THE TEXT

'如果为真,则显示文本

txtpass.UseSystemPasswordChar = False Else

txtpass.UseSystemPasswordChar = False Else

'IF FALSE, IT WILL HIDE THE TEXT AND IT WILL TURN INTO BULLETS.

'如果为假,它将隐藏文本并且它会变成子弹。

txtpass.UseSystemPasswordChar = True End If End Sub

txtpass.UseSystemPasswordChar = True End If End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'HIDE THE TEXT OF THE TXTPASS ON THE FIRST LOAD

'在第一次加载时隐藏 TXTPASS 的文本

txtpass.UseSystemPasswordChar = True End Sub End Class

txtpass.UseSystemPasswordChar = True End Sub End Class

回答by RBILLC

I ended up setting the font color for the text to the same as the background color.. and its gone:

我最终将文本的字体颜色设置为与背景颜色相同..它消失了:

<asp:CheckBox ID="cb_DataReview" class="standardCheckbox" runat="server" Width="90%" **ForeColor="white"** TabIndex="115" /> 

回答by philzy127

If I understand correctly, you just want the textbox to be unseen should this box be checked. Hope I'm reading that correctly. So you would just use the visible property.

如果我理解正确,您只是希望文本框在选中此框时不可见。希望我读对了。所以你只需要使用可见属性。

 Private Sub CheckBox17_CheckedChanged(ByVal sender As System.Object, 
ByVal e As System.EventArgs) Handles CheckBox17.CheckedChanged
        If CheckBox17.Checked = True Then
        TextBox1.Visible = False
        TextBox1.Enabled = False

    ElseIf CheckBox17.Checked = False Then
        TextBox1.Visible = True
        TextBox1.Enabled = True
    End If
End Sub

Is this what you were looking for?

这就是你要找的吗?