WinForm的自动缩放(跟随系统字体大小的改变)
当我们把系统的字体改为大字号的话,如果我们的Form上的text和control不跟着变大的话,那会使我们的界面很难看。但是很幸运的是在WinForm中已经提供了这个功能,使用也很方便,只需要在Form的Load事件中从新设置Form的字体为系统的字体。
二 请看效果如下:(均为系统字体为特大号时)
修改后:
修改前:
三 相关的代码1:
(注意上面代码中的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
二 请看效果如下:(均为系统字体为特大号时)
修改后:
修改前:
三 相关的代码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
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
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