0

我正在用c#开发一个项目。我的表单中有一个文本框,下面有一个按钮。我想通过单击按钮来更改文本框的可见性。例如,当表单加载时,文本框是隐藏的。当用户单击按钮,文本框出现在表单上。然后用户第二次再次单击它,文本框再次隐藏。我应该怎么做。请帮助我。

感谢您的帮助。

4

4 回答 4

4
private void button1_Click(object sender, EventArgs e)
{
    textBox1.Visible = !textBox1.Visible;
}
于 2013-04-09T12:27:54.683 回答
2

像这样的事情应该这样做

        private void button1_Click(object sender, EventArgs e)
        {
            tbProgress.Visible = !tbProgress.Visible;
        }
于 2013-04-09T12:27:51.260 回答
1
    bool showtext = false;

    public Form1()
    {
        InitializeComponent();
        textBox1.Visible = showtext;
        button1.Click += button1_Click;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        showtext = !showtext;
        textBox1.Visible = showtext;
    }
于 2013-04-09T12:26:13.753 回答
1
    public partial class Form1 : Form
    { 
        bool buttonvisible = false;

        public Form1()
        {
            InitializeComponent();
            button1.Visible = false;
            button1.Click += button1_Click;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(buttonvisible)
            {
                buttonvisible = false;
                button1.Visible = false;
            }
            else
            {
                buttonvisible = true;
                button1.Visible = true;
            }
        }
    }

或者简单,但不太可编辑:

private void button1_Click(object sender, EventArgs e)
{
    button1.Visible = !button1.Visible;
}
于 2013-04-09T12:29:31.883 回答