关于动态添加控件后移除控件的问题。。。。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
panel1.AutoScroll = true;
panel1.ControlRemoved += new ControlEventHandler( panel1_ControlRemoved );
}
void panel1_ControlRemoved( object sender , ControlEventArgs e )
{
System.Collections.IEnumerator enumerator = this.panel1.Controls.GetEnumerator();
int index = 0;
while ( enumerator.MoveNext() )
{
Control ctrl = (Control)enumerator.Current;
if ( index == 0 )
ctrl.Location = new Point( 0 , 0 );
else
ctrl.Location = new Point( 0 , ( index * ( 60 + 3 ) ) );
index++;
}
}
int height = 60;
private void button1_Click( object sender , EventArgs e )
{
Button btn = new Button();
btn.Width = panel1.Width-4;
btn.Height = height;