C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

WinForm的自动缩放(dialog跟随系统字体大小的自动缩放)

一   当我们把系统的字体改为大字号的话,如果我们的Form上的text和control不跟着变大的话,那会使我们的界面很难看。但是很幸运的是在WinForm中已经提供了这个功能,使用也很方便,只需要在Form的Load事件中从新设置Form的字体为系统的字体。

二  请看效果如下:(均为系统字体是特大号时)
       修改后:

      修改前:
三  相关的代码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;
        }

    }

}
相关代码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

        
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

posted on 2006-11-23 18:57 梦在天涯 阅读(3674) 评论(0)  编辑 收藏 引用 所属分类: CPlusPlusC#/.NET


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1785089
  • 排名 - 5

最新评论

阅读排行榜