C# 如何访问放置在面板中的控件值?
我在面板中有一个DropDownList控件,该面板依次放置在SplitContainer的panel1中。我将DropDownList的modifiers属性更改为“Public”,但无法从其他类访问此控件C# 如何访问放置在面板中的控件值?,c#,winforms,C#,Winforms,我在面板中有一个DropDownList控件,该面板依次放置在SplitContainer的panel1中。我将DropDownList的modifiers属性更改为“Public”,但无法从其他类访问此控件 //created instance of the form Payment pForm = new Payment(); 我可以访问位于拆分容器外部的其他控件,如下所示 string amount = pForm.tbAmount.Text; 但是我无法访问dropdownlist控
//created instance of the form
Payment pForm = new Payment();
我可以访问位于拆分容器外部的其他控件,如下所示
string amount = pForm.tbAmount.Text;
但是我无法访问dropdownlist控件。拆分容器有两个面板,每个面板都有一组控件,因此:
ComboBox dropdown = pForm
.SplitContainer1 // get the splitcontainer control of pForm
.Panel1 // get the first panel of this container
.Controls // get the controls collection
.OfType<ComboBox>() // find all controls that are of type ComboBox
.FirstOrDefault(); // get the first or null if none
拆分容器有2个面板,每个面板都有一组控件,因此:
ComboBox dropdown = pForm
.SplitContainer1 // get the splitcontainer control of pForm
.Panel1 // get the first panel of this container
.Controls // get the controls collection
.OfType<ComboBox>() // find all controls that are of type ComboBox
.FirstOrDefault(); // get the first or null if none