C# 怎样实现自动布局
描述:怎样实现通过按下一个按钮来删除某一个控件时,其他的控件会自动伸展以补齐空位,当下次需要显示该控件时其他控件就缩小,以腾出空间放下该控件?有什么思路?
程序代码:
private bool isMouseDown = false;
private int mouseX = 0;
private int baseWidth = 0;
private void listBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
this.listBox1.Width = baseWidth + e.X - mouseX;
if (this.listBox1.BorderStyle != BorderStyle.FixedSingle)
{
this.listBox1.BorderStyle = BorderStyle.FixedSingle;
}
}
else
{
int n = Math.Abs(e.X - this.listBox1.Width);
this.label1.Text = n.ToString();
if (n < 10)
{
if (this.Cursor != Cursors.SizeWE)
{
this.listBox1.Cursor = this.Cursor = Cursors.SizeWE;
}
}
else
{
if (this.Cursor != Cursors.Default)
this.listBox1.Cursor = this.Cursor = Cursors.Default;
}
}
}
private void listBox1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
if (this.listBox1.BorderStyle != BorderStyle.Fixed3D)
{
this.listBox1.BorderStyle = BorderStyle.Fixed3D;
}
}
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
isMouseDown = true;
baseWidth = this.listBox1.Width;
mouseX = e.X;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
listBox1_MouseMove(sender, e);
}
