0

Hi !!!

I have two Windows Forms. First Windows Form contain one Panel Control. This Panel Control contain other 5 child Label Controls. I wish from Second Windows Form get the number of child controls in Panel Control in First Windows Form and there Location?

// First Windows Form

public partial class FirstWForm : Form
{
public FirstWForm
{
    InitializeComponent();
}

private void AddLabelControlsToPanel()
{
    int position_X = 0;
    int position_Y = 0;

    for(int i = 0; i < 5; i++)
    {
       Label labelControl = new Label();
       labelControl.Point = 
            new Point(position_X, position_Y);

       this.panelControl.Controls.Add(labelControl);

       // put Label Controls in one under another ???
       position_Y += labelControl.Height
    }
}

public int CountChildInPanelControl()
{
    Control.ControlCollection ctrlCollection = this.panelControl.Controls;
    int countChild = ctrlCollection.Count;

    return countChild;
}
}


// Second Windows Form

public class SecondWForm
{
  private void Method()
  {
     FirstWForm firstWForm = new FirstWForm();
     int childInPanelControl = firstWForm.CountChildInPanelControl();

     // Some code here ...
     // Some code here ...
     // Some code here ...
     // Some code here ...
  }
}

In Second Windows Form when I call CountChildInPanelControl() method the returnet result is always zero '0'. Why ??? I don't understand !!! Sorry for my bad English !!!

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by destruct0
0

Where are you calling

AddLabelControlsToPanel()

method from?
I do not see it being called here, or am I missing something?

0

Is not important where i call AddLabelControlsToPanel() method. I wish to know how to get count of child controls in the Panel Control.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.