How to change all tab pages's title for a TabControl using C#


In some cases such as Multiple languages dynamically switching and if you have a main TabControl with some sub tab pages will be dynamically added into it, you might find it is not easy if you want to change all these dynamic tab pages.

Actually, if you have done Multiple languages dynamically switching mechanism in your code, for these dynamic tab pages, you can use the following code to "re-write" their title so that this title can get a chance to retrieve resource file and get text due to current cultural setting:

                for (int i = 0; i < tabControl.TabPages.Count; i++)
                    TabPage page = tabControl.TabPages[i];
                    string pTitle = "";
                    foreach (Control ctl in page.Controls)
                        if (ctl is Form)  //Asume tab page include the sub control which is Form
                            pTitle = ((Form)ctl).Text;  //The Text has already been set by cultural resource somewhere (before this block of code)
                    page.Title = pTitle;