我有一个 C# 表单选项卡应用程序。每个 TabPage 的左侧都有一个菜单(Outlook 样式的导航面板),右侧有一个内容面板。
如果我想要标签页 0 的内容面板,我该如何获取它?我有点困惑,因为我不知道如何索引选项卡页上的控件集合。下面用红色下划线表示,所以我认为它是错误的。
Panel panel = tabControl.TabPages[0].Controls["Panel"];
编辑:删除面板子问题中的窗口。它将被转移到一个单独的问题。
抱歉,对于初学者的问题。我是一个 C/C++ 人员,有很多 MFC 时间,而 C# UI 目前有点令人沮丧。
I have a C# Forms tab application. Each TabPage has a menu on the left (Outlook style navigation panel), and a Panel on the right for content.
If I want the content panel for tab page 0, how would I go about fetching it? I'm a bit stumped because I don't know how to index into the controls collection on a tab page. The following is underlined in red, so I believe its wrong.
Panel panel = tabControl.TabPages[0].Controls["Panel"];
EDIT: remove Window in Panel sub question. It will be moved to a separate question.
Sorry about the beginner questions. I'm a C/C++ guy with lots of MFC time, and C# UI is a bit frustrating at the moment.
发布评论
评论(4)
您始终可以在
control.Controls
上递归调用此函数来查找任何层次结构中的控件。control.Name
可用于查找您的特定控件。您无法在面板内显示表单。您可以创建自定义控件,您可以在其中添加功能并将该控件添加到面板中。
You can always call this recursively on
control.Controls
to find a control in any hierarchy.control.Name
can be used to find your specific control.You can't show a Form, inside a Panel. You could create Custom Control where you can add your functionality and add that control to a Panel.
例如,为了创建一个新表单,您需要创建一个您想要创建的表单的变量。
例如,
如果您想在面板中显示该表单,那么面板将是所有者,请记住所有者和父级之间的区别
请粘贴您迄今为止拥有的代码,我们可以建议必要的更改
in order to create a new form for example you need to create a variable of what ever form that it is you want to create.
example
if you want to show that form in the panel then the panel would be the Owner keep in mind the difference between Owner and Parent
please paste what ever code you have so far and we can suggest the necessary changes
最后,如何在面板中显示窗口?
- 您不想这样做。如果您希望窗口和面板共享一项 UI 功能,请创建一个具有所有功能的用户控件,然后可以将其放置在窗体或面板中。Finally, how does one display a Window in a Panel?
- you don't want to do that. If you want a window and a panel to share a piece of UI functionality, create a user control with all the the functionality and then you can place it in a form or in a panel.封装复杂 UI 内容的一种可能性是创建一个
用户控件
。通过这种方式,您可以创建一个可重用的复杂 UI,您基本上可以将其作为“blob”添加到表单中。之所以
带有红色下划线是因为
Controls
集合返回一个Control
可能是一个Panel
但也可能是其他东西。所以你需要转换它:另外:MSDN 有一些很好的资源 - 你应该利用它。
A possibility to encapsulate complex UI content is to create a
UserControl
. This way you can create a reusable piece of complex UI you can basically add as a "blob" inside a form.The reason why
is underlined red is because the
Controls
collection returns aControl
which might be aPanel
but also might be something else. So you need to cast it:Also: MSDN has some good resources - you should make use of it.