且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在窗口表单中使用Tab

更新时间:2023-10-19 18:04:22

您好,

希望这会对您有所帮助..我在其中放置了Tabcontrol1的Windows窗体.列表框具有五个值一个",两个",三个",四个",五个".每当我在列表框中选择一个项目时,代码都会检查是否打开了相应的标签页.如果没有tabpage,它将创建一个选项卡页面并将其添加到TabPage1.否则,如果页面已经存在,它将选择特定页面并返回.最初将标签页设置为0.希望这可以帮助您满足要求..

Hello,

Hope this will help you.. I have a windows form in that Tabcontrol1 is placed. The list box has five values "one", "two","three","four","five". Whenever I select an item in the list box the code will check for the corresponding tabpage is opened or not. If tabpage is not there it will create a tab page and add it to TabPage1. Otherwise if the page is already there it will select the particular page and return. Initially set the tabpages to 0. Hope this helps you to meet your requirement..

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
       {

           foreach (TabPage tp in tabControl1.TabPages)
           {
               //check for tag tile with the selected item in the list box
               if (tp.Text == listBox1.SelectedItem.ToString())
               {
                   //select the particular tabpage
                   tabControl1.SelectedTab = tp;
                   return;
               }
           }
           //if the tabpage is not found in the existing tabs it has to be created
           //crate a new tab
           TabPage newPage = new TabPage(listBox1.SelectedItem.ToString());
           tabControl1.TabPages.Add(newPage);

       }