将控件添加到选项卡页运行时
我使用 C# 和 winForms,我有一些选项卡控件,其中包含一些选项卡页面, 我想添加我的用户控制的所有选项卡页面,如果我可以在用户单击选项卡页面后添加它,那就最好了。它仅对我有用,当我在构造函数中添加此控件时 - 是什么导致应用程序启动时延迟 - 大约 3 秒,这非常多。
我想在运行时添加此控件,
tabPage1.onClickEvent()
{
tabPage1.Controls.Add(myUserControl);
}
但它不起作用,我也尝试使用 Invalidate 或 Refresh 方法,但它不起作用。
那么是否有可能在构造函数之外的其他方法中添加此 userControls ? 也许它的问题是,我在 TabControl 中有 TabControl 并且我必须通过父 TabControl 添加此控件? 谢谢!
I am using C# and winForms, I have a few tabcontrols, 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试双击设计器中的标签页,或者您可以像这样手动添加事件处理程序:
我不知道 tabPage1 是否是动态的,但如果不是,您应该将上述事件处理程序添加到您的 Designer.cs 文件中。
这是代码中的事件处理程序:
Try double clicking the tag page in the designer, or you can add the event handler manually like this:
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: