In c# how can I destroy a tab on a tab control by targeting it’s name? I’ve a tab named “Hello!” and I’d like to close it programatically. There’s no guarantee that it will be the selected tab at the time.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
TabControlclass provides aTabPagesproperty that returns aTabPageCollectioncontaining all of theTabPagesin the control.So you can use the
Itemproperty to retrieve theTabPagewith the specified name.For example, if the tab page you want is named “Hello!”, you would write:
To remove the
TabPagefrom the control, use theRemoveByKeymethod:Of course, in order for this to work, you’ll need to make sure that you’ve set the keys of your
TabPages to match the caption text they display.