开发者

How do I access combo box inside another interface panel in C#?

开发者 https://www.devze.com 2023-03-14 04:50 出处:网络
I have a parent form, which contains panels that calls different user control. For example, the file is something like this.

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?


you can use

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

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.

public delegate void MyEventHandler(object value);

event MyEventHandler MyEvent;

and raise the event when the control value is changed.

0

精彩评论

暂无评论...
验证码 换一张
取 消