利用窗體width動態改變窗體大小

每個窗體都有一個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就可以看到效果了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章