Create a winform program and drag a tabcontrol (delete two default tabpages in the tabpages attribute) and three buttons (add, delete, and modify)
- Public partial class form1: Form
- {
- Private int Index = 0;
- Public form1 ()
- {
- Initializecomponent ();
- }
- Private void form1_load (Object sender, eventargs E)
- {
- // This. tabcontrol1.selectedindex = 1;
- }
- Private void btnadd_click (Object sender, eventargs E)
- {
- Tabpage page = new tabpage ();
- Page. Name = "page" + index. tostring ();
- Page. Text = "tabpage" + index. tostring ();
- Page. tabindex = index;
- This. tabcontrol1.controls. Add (PAGE );
-
- # Region three methods to set a tab as the current tab
- // This. tabcontrol1.selectedindex = index;
- This. tabcontrol1.selectedtab = page;
- // This. tabcontrol1.selecttab ("page" + index. tostring ());
- # Endregion
- Index ++;
- }
- Private void btnremove_click (Object sender, eventargs E)
- {
- Bool first = true;
- If (index> 0)
- {
- # Region two ways to delete a tab
- This. tabcontrol1.controls. removeat (this. tabcontrol1.selectedindex );
- // This. tabcontrol1.controls. Remove (this. tabcontrol1.tabpages [This. tabcontrol1.tabpages. Count-1]);
- # Endregion
- }
- Else
- {
- Return;
- }
-
- # Region is used to delete the last tabpage and set the last and second to the current tab.
- If (first)
- {
- This. tabcontrol1.selectedindex = -- index-1;
- First = false;
- }
- Else
- {
- This. tabcontrol1.selectedindex = index --;
- }
- # Endregion
- }
- Private void btnupdate_click (Object sender, eventargs E)
- {
- This. tabcontrol1.selectedtab. Text = "xyt"; // modify the attributes of the current tab.
- // This. tabcontrol1.selectedtab. Name = "";
- // This. tabcontrol1.selectedtab. Tag = "";
- // This. tabcontrol1.selectedtab. Select ();
- }
- }