WinForm的自動縮放(dialog跟隨系統(tǒng)字體大小的自動縮放)
一?? 當(dāng)我們把系統(tǒng)的字體改為大字號的話,如果我們的Form上的text和control不跟著變大的話,那會使我們的界面很難看。但是很幸運(yùn)的是在WinForm中已經(jīng)提供了這個功能,使用也很方便,只需要在Form的Load事件中從新設(shè)置Form的字體為系統(tǒng)的字體。
二? 請看效果如下:(均為系統(tǒng)字體是特大號時(shí))
?????? 修改后:
????? 修改前:
三? 相關(guān)的代碼1:
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Text;
using?System.Windows.Forms;

namespace?WinFormAutoScale


{
????public?partial?class?Form1?:?Form

????
{
????????public?Form1()

????????
{
????????????InitializeComponent();
????????}

????????private?void?Form1_Load(object?sender,?EventArgs?e)

????????
{
????????????this.Font?=?SystemFonts.IconTitleFont;
????????}
????}
}相關(guān)代碼2:
namespace?WinFormAutoScale


{
????partial?class?Form1

????
{

????????/**////?<summary>
????????///?Required?designer?variable.
????????///?</summary>
????????private?System.ComponentModel.IContainer?components?=?null;


????????/**////?<summary>
????????///?Clean?up?any?resources?being?used.
????????///?</summary>
????????///?<param?name="disposing">true?if?managed?resources?should?be?disposed;?otherwise,?false.</param>
????????protected?override?void?Dispose(bool?disposing)

????????
{
????????????if?(disposing?&&?(components?!=?null))

????????????
{
????????????????components.Dispose();
????????????}
????????????base.Dispose(disposing);
????????}


????????Windows?Form?Designer?generated?code#region?Windows?Form?Designer?generated?code


????????/**////?<summary>
????????///?Required?method?for?Designer?support?-?do?not?modify
????????///?the?contents?of?this?method?with?the?code?editor.
????????///?</summary>
????????private?void?InitializeComponent()

????????
{
????????????System.ComponentModel.ComponentResourceManager?resources?=?new?System.ComponentModel.ComponentResourceManager(typeof(Form1));
????????????this.label1?=?new?System.Windows.Forms.Label();
????????????this.button1?=?new?System.Windows.Forms.Button();
????????????this.SuspendLayout();
????????????//?
????????????//?label1
????????????//?
????????????resources.ApplyResources(this.label1,?"label1");
????????????this.label1.BorderStyle?=?System.Windows.Forms.BorderStyle.FixedSingle;
????????????this.label1.Name?=?"label1";
????????????//?
????????????//?button1
????????????//?
????????????resources.ApplyResources(this.button1,?"button1");
????????????this.button1.Name?=?"button1";
????????????this.button1.UseVisualStyleBackColor?=?true;
????????????//?
????????????//?Form1
????????????//?
????????????resources.ApplyResources(this,?"$this");
????????????this.AutoScaleMode?=?System.Windows.Forms.AutoScaleMode.Font;
????????????this.Controls.Add(this.button1);
????????????this.Controls.Add(this.label1);
????????????this.Name?=?"Form1";
????????????this.Load?+=?new?System.EventHandler(this.Form1_Load);
????????????this.ResumeLayout(false);
????????????this.PerformLayout();

????????}

????????#endregion

????????private?System.Windows.Forms.Label?label1;
????????private?System.Windows.Forms.Button?button1;
????}
}


(注意上面代碼中的Form的AutoScaleMode屬性的設(shè)置)
四? 求助:在MFC中的Dialog并沒有提供類似的功能,要實(shí)現(xiàn)Dialog的自動的縮放,要使Dialog上texts和controls都隨著系統(tǒng)的字體大小縮放,而且還不僅跟字體有關(guān)。那位有好的辦法,謝謝!
五? 參考:
?????????http://m.shnenglu.com/mzty/archive/2006/11/13/15131.html
?????????http://msdn2.microsoft.com/en-us/library/ms229605.aspx
二? 請看效果如下:(均為系統(tǒng)字體是特大號時(shí))
?????? 修改后:
????? 修改前:
三? 相關(guān)的代碼1:

















































































































(注意上面代碼中的Form的AutoScaleMode屬性的設(shè)置)
四? 求助:在MFC中的Dialog并沒有提供類似的功能,要實(shí)現(xiàn)Dialog的自動的縮放,要使Dialog上texts和controls都隨著系統(tǒng)的字體大小縮放,而且還不僅跟字體有關(guān)。那位有好的辦法,謝謝!
五? 參考:
?????????http://m.shnenglu.com/mzty/archive/2006/11/13/15131.html
?????????http://msdn2.microsoft.com/en-us/library/ms229605.aspx
posted on 2006-11-23 18:57 夢在天涯 閱讀(3718) 評論(0) 編輯 收藏 引用 所屬分類: CPlusPlus 、C#/.NET