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