每個窗體都有一個Width和Height屬性,可以控制窗體的寬高,利用timer和width可以實現窗口的動態變化
先添加一個timer控件,雙擊timer控件添加代碼如下:
private void timer1_Tick(object sender, EventArgs e)
{
if (StateOfRight == 1)
{
if (this.Width < 930)
{
this.Width = this.Width + 40;//窗體大小改變
}
else
{
timer1.Enabled = false;
}
}
else
{
if (this.Width > 685)
{
this.Width = this.Width - 40;
}
else
{
timer1.Enabled = false;
}
}
}
添加一個按鈕控件,讓timer1.Enabled = true就可以看到效果了