MFC對話框控件隨對話框的大小變化

//控件隨窗體自動縮放
            string[] tmp = new string[2];

            tmp = ((Form)sender).Tag.ToString().Split(',');

            float width = (float)((Form)sender).Width / (float)Convert.ToInt16(tmp[0]);
            float heigth = (float)((Form)sender).Height / (float)Convert.ToInt16(tmp[1]);

            ((Form)sender).Tag = ((Form)sender).Width.ToString() + "," + ((Form)sender).Height;

            foreach (Control control in ((Form)sender).Controls)
            {
                control.Scale(new SizeF(width, heigth));
            }

使用該代碼注意事項:1,此段代碼基本通用。2,此段代碼寫在窗體的加載事件中。3,若窗體需要縮小,請再寫在窗體的SizeChanged事件中。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章