Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to create an UI in windows form with a check box and abd two text box (txtbox1 and txtbox2). When check box is unchecked i want to make both txtbox1 and txtbox2 visible but when checkbox is checked only text box1 to be visible. I would appreciate the help and suggestion. Thank you.
Posted
Comments
Michael_Davies 15-Jan-16 2:56am    
What have you tried?

Trap the CheckedChanged event for the checkbox set txtbox2.visible = NOT checkbox.checked; I think ! is NOT in C#...

1 solution

Try this
C#
private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkBox1.Checked)
            {
                textBox1.Visible = true;
                textBox2.Visible = true;
            }
            else
            {
                textBox2.Visible = false;
            }
        }
 
Share this answer
 
Comments
[no name] 15-Jan-16 3:18am    
thank you it worked.
[no name] 15-Jan-16 3:34am    
when form load i want the invisible text box to be invisible also .
[no name] 15-Jan-16 3:40am    
on form load event i made txtbox prop to false. :)
yourfriendaks 15-Jan-16 3:56am    
using control properties, set visible to false also you can do that. Setting Properties in designer is best practice instead of writing on load event

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900