Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何访问放置在面板中的控件值?_C#_Winforms - Fatal编程技术网

C# 如何访问放置在面板中的控件值?

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控

我在面板中有一个DropDownList控件,该面板依次放置在SplitContainer的panel1中。我将DropDownList的modifiers属性更改为“Public”,但无法从其他类访问此控件

//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