濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > C#實(shí)現(xiàn)窗體中的各個(gè)控件同比自動(dòng)放縮大小

C#實(shí)現(xiàn)窗體中的各個(gè)控件同比自動(dòng)放縮大小

熱門標(biāo)簽:智能電銷機(jī)器人銷售話術(shù) 兗州電話外呼營(yíng)銷系統(tǒng) 機(jī)器人外呼系統(tǒng)軟件存在問題 南京400電話怎樣辦理 企業(yè)智能外呼系統(tǒng)價(jià)格多少 徐州ai電銷機(jī)器人原理 沈陽(yáng)營(yíng)銷電銷機(jī)器人招商 福州電銷機(jī)器人源代碼 高德地圖標(biāo)注商戶位置

實(shí)現(xiàn)方式主要是利用panel控件為主題,對(duì)于每個(gè)控件的大小位置和字體這幾個(gè)屬性進(jìn)行記錄,然后根據(jù)窗體改變的大小同時(shí)放縮。

簡(jiǎn)要步驟如下:

1、創(chuàng)建C#窗體程序項(xiàng)目。
2、Panel放置到窗體。
3、設(shè)置屬性dock為fill。
4、注意MinnumSize不能設(shè)置為0, 改成大于0都行。

復(fù)制代碼 代碼如下:

public partial class FrmDemo : Form 
    { 
        double dFrmWidth; 
        double dFrmHeight; 
        double dZoomHorizon; 
        double dZoomVerticality; 
        Dictionarystring, string> dicControlsAttribute = new Dictionarystring, string>(); 
 
        protected void GetAllInitiateContrlInfo(Control CrlContainer) 
        { 
            if (CrlContainer.Parent == this) 
            { 
                dFrmWidth = Convert.ToDouble(CrlContainer.Width); 
                dFrmHeight = Convert.ToDouble(CrlContainer.Height); 
            } 
            foreach (Control item in CrlContainer.Controls) 
            { 
                if (item.Name.Trim() != "") 
                    dicControlsAttribute.Add(item.Name, (item.Left + item.Width / 2) + "," + (item.Top + item.Height / 2)  
                                             + "," + item.Width + "," + item.Height + "," + item.Font.Size); 
                if ((item as UserControl) == null item.Controls.Count > 0) 
                    GetAllInitiateContrlInfo(item); 
            } 
        } 
 
        private void ChangeControlsInitiate(Control CrlContainer) 
        { 
            dZoomHorizon = (Convert.ToDouble(CrlContainer.Width) / dFrmWidth); 
            dZoomVerticality = (Convert.ToDouble(CrlContainer.Height) / dFrmHeight); 
        } 
         
        private void ChangeCurrentControlAttr(Control CrlContainer) 
        { 
            double[] dPosition = new double[5]; 
            foreach (Control item in CrlContainer.Controls) 
            { 
                if (item.Name.Trim() != "") 
                { 
                    if ((item as UserControl) == null item.Controls.Count > 0) 
                        ChangeCurrentControlAttr(item); 
                    string[] strs = dicControlsAttribute[item.Name].Split(','); 
                    for (int j = 0; j 5; j++) 
                    { 
                        dPosition[j] = Convert.ToDouble(strs[j]); 
                    } 
                    double itemWidth = dPosition[2] * dZoomHorizon; 
                    double itemHeight = dPosition[3] * dZoomVerticality; 
                    item.Left = Convert.ToInt32(dPosition[0] * dZoomHorizon - itemWidth / 2); 
                    item.Top = Convert.ToInt32(dPosition[1] * dZoomVerticality - itemHeight / 2); 
                    item.Width = Convert.ToInt32(itemWidth); 
                    item.Height = Convert.ToInt32(itemHeight); 
                    //item.Font = new Font(item.Font.Name, float.Parse 
                    //((dPosition[4] * Math.Min(dZoomHorizon, dZoomVerticality)).ToString())); 
                    //字體也可以實(shí)現(xiàn)同比放縮。 
                     } 
            } 
        } 
        protected override void OnSizeChanged(EventArgs e) 
        { 
            base.OnSizeChanged(e); 
            if (dicControlsAttribute.Count > 0) 
            { 
                ChangeControlsInitiate(this.Controls[0]); 
                ChangeCurrentControlAttr(this.Controls[0]); 
            } 
        }  
 
        public FrmDemo() 
        { 
            InitializeComponent(); 
            GetAllInitiateContrlInfo(this.Controls[0]);//構(gòu)造函數(shù)里面調(diào)用即可。 
        } 
}

5、效果測(cè)試

您可能感興趣的文章:
  • C#中登錄窗體和歡迎窗體關(guān)閉方法分析
  • C#設(shè)置窗體最大化且不遮擋任務(wù)欄的方法
  • C#窗體傳值實(shí)例匯總
  • C#全局熱鍵設(shè)置與窗體熱鍵設(shè)置實(shí)例
  • C#定時(shí)關(guān)閉窗體實(shí)例
  • C#實(shí)現(xiàn)隨鼠標(biāo)移動(dòng)窗體實(shí)例
  • C# Winform實(shí)現(xiàn)捕獲窗體最小化、最大化、關(guān)閉按鈕事件的方法
  • C#入門之窗體的簡(jiǎn)單用法實(shí)例

標(biāo)簽:大理 昭通 景德鎮(zhèn) 鶴崗 吉安 丹東 本溪 邯鄲

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《C#實(shí)現(xiàn)窗體中的各個(gè)控件同比自動(dòng)放縮大小》,本文關(guān)鍵詞  實(shí)現(xiàn),窗體,中的,各個(gè),控件,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《C#實(shí)現(xiàn)窗體中的各個(gè)控件同比自動(dòng)放縮大小》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于C#實(shí)現(xiàn)窗體中的各個(gè)控件同比自動(dòng)放縮大小的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    古丈县| 长阳| 革吉县| 浮山县| 调兵山市| 碌曲县| 南城县| 西城区| 高台县| 阆中市| 邓州市| 尼勒克县| 咸宁市| 页游| 莲花县| 民乐县| 政和县| 璧山县| 龙游县| 抚远县| 南皮县| 耒阳市| 盐城市| 无极县| 筠连县| 衡山县| 枞阳县| 高清| 清涧县| 郧西县| 包头市| 平谷区| 嘉兴市| 丰镇市| 久治县| 明溪县| 新昌县| 桑日县| 同德县| 韩城市| 耒阳市|