c# - Iterating through controls on a Windows Form -


I think there is some strange issue going on that I'm sure will turn off for a simple thing I have a windows form and on the form I have 1 panel inside the main panel and the main panel, I have a panel inside and a label that is inside the main panel, but not in the second panel. 2 Control what I am trying to do is copying all the Menon panel controls into another panel object. I am using the following C # code to do this:

  GUIPanel GP = new GUIPANEL (); Foreach (system.Windows.Forms.Control ctrl in gp.Controls ["MainPanel"]. Control) {m_OptionsControl.Controls.Add (ctrl); }  

When I run this code, it copies it to the panel with the button, but the label is not what is even weird when I set a breakpoint and it's debugger Run through, and I type "gp.Controls [" MainPanel "]. Control window However, while stepping through the code, it only executes the foreach loop once. What am I missing here?

WinForms control can not be copied; Your code will not work properly
When you add control to the second panel, it will first be removed from the panel.

You can move all the controls using a reverse loop.
You can copy the controls by creating a new example of each control and copying all the properties.

Edit : For example:

 for  (int i = man panel. Control calculation - 1; i & gt; = 0; i--) {MainPanel.Controls [i] Parent = m_OptionsControl; }  

Comments