2016-11-20 5 views
1

パネルを含むユーザー定義コントロールを作成し、パネル内にラベルとテキストボックスを作成しました。さて、私の親のフォームには、フローレイアウトパネルがあります。私は、ユーザ定義のコントロールをflowlayoutパネルに追加しています。ここで親フォームのユーザー定義コントロールからコントロールの値を取得する方法

user-defined control

flowlayout panel

私は制御値を取得するために使用していますが、常に私がListBoxコントロールの値を確認与えているコードです:

// Here 'panel_Attribute' is my parent form panel to which I have added the controls 
Control.ControlCollection listControls = panel_Attribute.Controls; 
foreach (Control attributeControl in listControls) 
{ 
    if (attributeControl is Control) 
    { 
    log.Debug("attributeControl Values are attributeControl attributeControl.Name" + 
     attributeControl.Name + ", Value: " + attributeControl.Text); 

    attributeList.Add(((PHShowAttributeControl)attributeControl). 
     ProbeRawProjectTaskAttributeEvent); 
    //attributeList.Add(GetControlValues()); 
    } 
} 
+0

'(UserControlとしてWindow.Controls [x]).Control.Property'? –

答えて

0

あなたのユーザーコントロールを追加する場合あなたのParentFormにデザイナーがそれを作成し、それに直接アクセスできます。例えば

myUserControl.Enable = false; 

あなたParentFormはUserControlの中にあなたのコントロールについて何かを知っている必要はありません。ちょうどあなたのUserControlいくつかのプロパティを過ごす。お客様からの名前のテキストボックスがあるとします:

public class MyUserControl : UserControl 
{ 
    public string Name 
    { 
     //Inside your UserControl you can access your Controls directly 
     get{return textBoxName.Text;} 
     set {textBoxName.Text = value;} 
    } 
} 

public class MyForm : Form 
{ 
    //This set the Text in your UserControl Textbox. 
    myUserControl.Name = "Mr. Example"; 
} 

私はこれがあなたに役立つことを願っています。

関連する問題