添加按钮,一个TabControl选项卡在C# [英] Adding buttons to a TabControl Tab in C#

查看:941
本文介绍了添加按钮,一个TabControl选项卡在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个windows窗体一个TabControl。我已经pragmaticly增加了新的标签,像这样:

I have a TabControl in a windows form. I have pragmaticly added new tabs like so:

for (int i = 1; i < numOfLanguages; i++)
{
     // add a tab for each language
     string tabTitle = split[i];
     TabPage newTab = new TabPage(tabTitle);
     languageTabs.TabPages.Add(newTab);
}

循环我想设置其他controlls为每个标签内。主要是我想补充的按钮。我已经看到了这code:

inside the loop I want to set up the other controlls for each tab. mainly I want to add buttons. I have seen this code:

tabPage1.Controls.Add(new Button());

根据离这个例子,我希望做同样的事情,如:

Based off this example I want to do something similar like:

languageTabs.SelectTab(split[i]).Add(new Button());

我知道,这code不会工作。一直在寻找通过PARAMS和无法看到任何东西,让我做这种事情。

I know that this code wont work. Have been looking through the params and cant see anything that lets me do this kind of thing.

任何想法社区?

推荐答案

SelectTab 移动实际的TabControl 来的指定标签,它不返回的标签让你操纵它。

SelectTab moves the actual TabControl to the specified tab, it does not return the tab to let you manipulate it.

您可以索引标签页如下:

You can index into the tab pages as follows:

languageTabs.TabPages[2].Controls.Add(new Button());

如果您已设置 名称 上的的TabPage 对创造,那么你也可以找到关键的各个选项卡属性:

If you have set the Name property on the TabPage on creation, then you can also find individual tabs by key:

for (int i = 1; i < numOfLanguages; i++)
{
     // add a tab for each language
     string tabTitle = split[i];
     TabPage newTab = new TabPage(tabTitle);
     newTab.Name = tabTitle;
     languageTabs.TabPages.Add(newTab);
}

...

languageTabs.TabPages[split[i]].Controls.Add(new Button());

中查看MSDN

无论是最方便的。

这篇关于添加按钮,一个TabControl选项卡在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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