如何在 C# 中访问另一个界面面板内的组合框?

发布于 2024-11-16 05:23:52 字数 444 浏览 5 评论 0原文

我有一个父窗体,其中包含调用不同用户控件的面板。 例如,该文件是这样的。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一萌ing 2024-11-23 05:23:52

如果指定的控件存在,您可以使用

this.Controls.Find("YourControlName", true);

它返回一个控件集合

you can use

this.Controls.Find("YourControlName", true);

this will return a control collection if specified control exists

等风来 2024-11-23 05:23:52

我建议在接口中定义事件并在父窗体中处理事件。在事件中将值作为参数传递。

public delegate void MyEventHandler(object value);

event MyEventHandler MyEvent;

并在控制值更改时引发事件。

I suggest that define event in interface and handle the event in parent form. In event pass the value as argument.

public delegate void MyEventHandler(object value);

event MyEventHandler MyEvent;

and raise the event when the control value is changed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文