二 请看效果如下:( 均为系统字体为特大号时)
修改后:
修改前:
三 相关的代码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
this.style.display='none'; Codehighlighter1_193_455_Open_Text.style.display='none'; Codehighlighter1_193_455_Closed_Image.style.display='inline'; Codehighlighter1_193_455_Closed_Text.style.display='inline';" src="https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top> {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Font = SystemFonts.IconTitleFont;
}
}
}
相关代码2:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WinFormAutoScale
this.style.display='none'; Codehighlighter1_193_455_Open_Text.style.display='none'; Codehighlighter1_193_455_Closed_Image.style.display='inline'; Codehighlighter1_193_455_Closed_Text.style.display='inline';" src="https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top> {
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Font = SystemFonts.IconTitleFont;
}
}
}
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;
}
}
{
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属性的设置)
四 求助:在MFC中的Dialog并没有提供类似的功能,要实现Dialog的自动的缩放,要使Dialog上texts和controls都随着系统的字体大小缩放,而且还不仅跟字体有关。那位有好的办法,谢谢!
五 参考:
http://www.cppblog.com/mzty/archive/2006/11/13/15131.html
http://msdn2.microsoft.com/en-us/library/ms229605.aspx