如何在 C# 中访问另一个界面面板内的组合框?
我有一个父窗体,其中包含调用不同用户控件的面板。 例如,该文件是这样的。
Form1.cs->包含主面板
selectioninterface.cs ->包含一个动态更改面板(界面1或界面2)的组合框
interface1.cs 接口2.cs->其中包含一个单独的面板,form1.cs 在其面板内调用该面板。
我目前正在使用它循环浏览 form1 面板。
foreach(Control control in panel.Controls) {
if(control.GetType() == typeof(selectioninterface))
{
}
}
我得到了这一部分,但我需要访问位于界面 1 和界面 2 面板内的文本框和组合框信息。我如何访问它们?
I have a parent form, which contains panels that calls different user control.
For example, the file is something like this.
Form1.cs -> Contains the main panel
selectioninterface.cs -> Contains a combobox which dynamically changes the panel(interface1 or interface2)
interface1.cs
interface2.cs -> These contains a separate panel which form1.cs calls inside its panel.
I am currently looping through the form1 panel using this.
foreach(Control control in panel.Controls) {
if(control.GetType() == typeof(selectioninterface))
{
}
}
I got this part, but I need to access the textbox and combobox information located inside the interface1 and interface2 panels. How do I access them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果指定的控件存在,您可以使用
它返回一个控件集合
you can use
this will return a control collection if specified control exists
我建议在接口中定义事件并在父窗体中处理事件。在事件中将值作为参数传递。
并在控制值更改时引发事件。
I suggest that define event in interface and handle the event in parent form. In event pass the value as argument.
and raise the event when the control value is changed.