如何创建动态选项卡控件以及如何在c#中创建动态点击页面? [英] how to create dynamic tab control and how to create dynamic tap pages in c# ?
问题描述
我是C#程序员的初学者,所以我在创建动态标签控件和点击页面时遇到问题.请帮我!!!
i am beginner of c# programmer so i have problem to create dynamic tab control and tap pages. please help me !!!
推荐答案
动态添加任何控件时,请先创建该控件的实例
When adding any control dynamically, first create an instance of the control
TabControl tc = new TabControl();
然后您可能需要定位它并更改其他一些属性,例如
Then you will probably need to position it and change some other properties e.g.
tc.Top = 145;
tc.Left = 150;
tc.Name = "DynamicTabControl";
向其中添加一些标签页...
Add some tab pages to it...
tc.TabPages.Add("My 1st Tab");
tc.TabPages.Add("My 2nd Tab");
您可能还需要添加一些事件处理程序,以便知道例如在选项卡之间移动的时间
You will probably want to add some event handlers too, so that you know when you have moved between tabs for example
tc.SelectedIndexChanged += new System.EventHandler(tabControl1_SelectedIndexChanged);
,并且需要记住将其添加到表单
And you need to remember to add it to the controls collection for the form
this.Controls.Add(tc);
的控件集合中.
这是我设置的事件处理程序的示例
Here''s an example of that event handler I set up
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
TabControl tc1 = (TabControl)sender;
MessageBox.Show(tc1.SelectedIndex.ToString());
}
If you want to add further tabs later on see reference[^]
An example:
private void button3_Click(object sender, EventArgs e)
{
// NB Find returns an array of controls - see the [0] at the end here...
TabControl tc1 = (TabControl)this.Controls.Find("DynamicTabControl", true)[0];
tc1.TabPages.Add("A 3rd Tab");
}
这篇关于如何创建动态选项卡控件以及如何在c#中创建动态点击页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!