开发者

Adding controls to tab page runtime

I am using C# and winForms, I have a few tab开发者_高级运维controls, which contains a few tab pages, I would like to add all tab pages my user control, it would be best, If I could add it after user click on tab page. It works for me only, when I add this controls in constructor - what makes delay at application start - about 3 seconds, what is very much.

I would like to add this controls at run time, like

tabPage1.onClickEvent()
{
tabPage1.Controls.Add(myUserControl);
}

but it didnt works, I also tryied to use Invalidate, or Refresh method but it not works.

So is there any possibility to add this userControls in other method than constructor? Maybe its problem, that I have TabControl inside TabControl and I have to add this controls throught parent TabControl? Thanks!


Try double clicking the tag page in the designer, or you can add the event handler manually like this:

tabPage1.Click += new EventHandler(tagPage1_Click);

I don't know whether tabPage1 is dynamic, but if it's not, you should add the above event handler to your designer.cs file.

Here is the event handler in the code:

protected void tabPage1_Click(object sender, EventArgs e)
{
    tagPage1.Controls.Add(new TextBox());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜