问题
I'm working on a windows form application and I have a button and a textbox
in it.
When the button is pressed, it should make the textbox
visible and hidden.
回答1:
myTextbox.Visible = !myTextbox.Visible;
回答2:
Did you try Google?
textBox1.Visible = false;
You can toggle the visibility by doing:
if(textBox1.Visible == true)
textBox1.Visible = false;
else
textBox1.Visible = true;
回答3:
WinForm:
private void button1_Click(object sender, System.EventArgs e)
{
textBox.Visible = !textBox.Visible;
}
WPF:
private void button1_Click(object sender, RoutedEventArgs e)
{
if (textBox.Visibility != System.Windows.Visibility.Hidden)
textBox.Visibility = System.Windows.Visibility.Hidden;
else
textBox.Visibility = System.Windows.Visibility.Visible;
}
回答4:
You can find an example here
private void button1_Click(object sender, System.EventArgs e)
{
/* If the CTRL key is pressed when the
* control is clicked, hide the control. */
if(Control.ModifierKeys == Keys.Control)
{
((Control)sender).Hide();
}
}
回答5:
textbox.visible=true;
you should try this on buttonClick event
来源:https://stackoverflow.com/questions/14250082/making-text-box-visible-unvisible-c-sharp