Start New Discussion within our Software Development Community

I am writing a code and I am somewhat new and this is kinda throwing me off. Here is my code:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                textBox4.Visible = true;
                textBox5.Visible = true;
            }
            else
            { 
                textBox4.Visible = false;
                textBox5.Visible = false;
            }
                
            

                
        }
        }
    }

Now when I run this code and try to check the checkbox nothing happens. I don't have an error coming up or nothing but it is not working.When the user check the checkbox it needs to be visible. And when they uncheck the checkbox I need it to go hide.

Your code is fine. you just need to hide textboxes when form load. So, when your checkbox checked it will be visible :

private void Form1_Load(object sender, EventArgs e)
     {
        textBox4.Visible = false;
        textBox5.Visible = false;
     }
private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox1.Checked)
        {
            textBox$.Visible = true;
            textBox5.Visible = true;
        }
        else
        {
            textBox4.Visible = false;
            textBox5.Visible = false;
        }
    }
This question has already been answered. Start a new discussion instead.