在窗口表单中使用Tab [英] Working with Tab in Window form

查看:63
本文介绍了在窗口表单中使用Tab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序员们,我有一个Window窗体,其中包含一个TabControl,在运行时为空,我还有一个列表框,其名称与用户控件相关联,当从列表框中选择名称时,我希望检查选项卡页面之前是否已经打开过,如果是,则什么都不做,但是如果该选项卡尚未打开,则会打开新选项卡..到目前为止,我已经尝试将列表框中所选项目的文本与标题进行比较.标签页已经打开,但是不起作用...我该怎么办..谢谢

Hi fellow programmers i have a Window form that contains a TabControl which is empty at runtime, i also have a listbox with name of form associated to a user control, when selecting the name from the listbox, i want to be able to check if the tabpage has already been opened before, if yes it does nothing but if that tab has not been opened it opens the new tab.. So far i have tried to compare the text of the selected item in the listbox to the titles of the tabpages already open, but it does not work... What should i do.. Thanks

推荐答案

您好,

希望这会对您有所帮助..我在其中放置了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);

       }


这篇关于在窗口表单中使用Tab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆