C# 中的选项卡式用户界面
我想创建一个简单的选项卡式界面应用程序。 我之前在 WPF 中使用每个选项卡内的用户控件进行了此操作,并且我与主要表单进行通信以搜索父元素(表单或选项卡控件),
我如何在 WinForms 中进行相同的操作? 我需要在每个选项卡中放置哪些元素?
谢谢。
I want to create a simple tabbed interface app. I did it before in WPF using an usercontrol inside of each tab, and I comunicate with the principal form searching for a parent element (the form, or the tab control)
How could I made the same in WinForms? Which element need I put inside of each tab?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 winforms 应用程序中使用几乎相同的方法。 您可以将用户控件添加到 TabControl< 的选项卡页/a> 在表单上。 在用户控制代码中,您可以使用 FindForm< /a> 方法来获取父窗体。
但是,我建议您改为使用事件来与控件“向外”进行通信,以便减少它们对周围环境的依赖。
You can use pretty much the same approach in a winforms application. You can add user controls to the tab pages of a TabControl on a form. Inside the user control code you can use the FindForm method to get hold of the parent form.
However, I would suggest that you instead use events to communicate "out" from the controls, in order to make them less dependent on their surroundings.
TabPage 和 TabControl 可能是您想要研究的类和组件。 使用 Parent 属性,您可以访问所属表单,从而在需要时与其进行通信或在选项卡之间进行通信。
不过,正如 Fredrik Mörk 所建议的那样,使用事件是一种更好的做法。 =)
TabPage and TabControl might be classes and components you would want to look into. Using the Parent property you can access the owning form and thus communicate with it or between tabs, should you need it.
Though, as Fredrik Mörk suggests, using events is a far better practice. =)