本文介绍了如何从面板中取出控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从一个面板中取出控件并将该控件存储在另一个面板中.

示例:
我有两个面板
1.panel1
2.panel2

我在panel1中添加了一个按钮.一段时间后,我想将panel1控件添加到panel2中.

请提出解决此问题的方法.

谢谢

How to take out controls from one panel and store that controls in another panel.

Example:
I have two panel
1.panel1
2.panel2

I added a button into the panel1.After some time i want to add the panel1 controls into panel2.

Please suggest how to solve this problem.

Thanks

推荐答案

foreach (Control c in Panel1.Controls)
   {
   Panel2.Controls.Add(c); 
   } 
Panel1.Controls.Clear();




如何将控件从panel1反向放置到panel2中.
意思是:如果panel1包含2个control.pos1.Label和pos2.Button

我想在第一个位置显示按钮,在第二个位置显示标签.

请帮忙.

谢谢"



试试:




"How can i put controls in panel2 from panel1 in reverse manner.
Means:If panel1 contains 2 controls.pos1.Label and pos2.Button

I want to show the button in first position and label in second position.

Please help.

Thanks"



Try:

for (int i = Panel1.Controls.Count - 1; i >= 0; i--)
    {
    Panel2.Controls.Add(panel1.Controls[i]);
    }


这篇关于如何从面板中取出控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 05:04