zoukankan      html  css  js  c++  java
  • C#GDI+的字体设置

    在GDI+中可以用FontFamily和Font设置字体,其中FontFamily构造函数带一字体参数,如:FontFamily ff = new FontFamily("Times New Roman");

    Font类则有多个重载的函数:

      Font(IntPtr)  基础结构。使用指定的指针初始化新的 Font。
      Font(Font, FontStyle)  初始化新 Font,它使用指定的现有 Font 和 FontStyle 枚举。
      Font(FontFamily, Single)  使用指定的大小初始化新 Font。
      Font(String, Single)  使用指定的大小初始化新 Font。 
      Font(FontFamily, Single, FontStyle)  使用指定的大小和样式初始化新 Font。
      Font(FontFamily, Single, GraphicsUnit)  使用指定的大小和单位初始化新的 Font。将此样式设置为 FontStyle..::.Regular。 
      Font(String, Single, FontStyle)  使用指定的大小和样式初始化新 Font。
      Font(String, Single, GraphicsUnit)  使用指定的大小和单位初始化新的 Font。将样式设置为 FontStyle..::.Regular。
      Font(FontFamily, Single, FontStyle, GraphicsUnit)  使用指定的大小、样式和单位初始化新的 Font。
      Font(String, Single, FontStyle, GraphicsUnit)  使用指定的大小、样式和单位初始化新的 Font。
      Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)  使用指定的大小、样式、单位和字符集初始化新的 Font。
      Font(String, Single, FontStyle, GraphicsUnit, Byte)  使用指定的大小、样式、单位和字符集初始化新的 Font。
      Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)  使用指定的大小、样式、单位和字符集初始化新的 Font。
      Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)  使用指定的大小、样式、单位和字符集初始化新 Font。

    最后用Graphics类的DrawString方法:

    e.Graphics.DrawString("你好", new Font(new FontFamily("黑体"),12), Brushes.Black, new PointF(5,5));

    示例代码如下:

     

    1 private void Form1_Paint(object sender, PaintEventArgs e)
    2 {
    3 Graphics g = e.Graphics;
    4 g.FillRectangle(Brushes.White,this.ClientRectangle);
    5
    6 FontFamily ff = new FontFamily("Times New Roman");
    7 Font f = new Font(ff, 12);
    8 string s = "Height: " + f.Height;
    9 SizeF sf = g.MeasureString(s, f, Int32.MaxValue, StringFormat.GenericTypographic);
    10 RectangleF r = new RectangleF(0, 0, sf.Width, f.Height);
    11 g.DrawRectangle(Pens.Black, r.Left, r.Top, r.Width, r.Height);
    12 g.DrawString(s, f, Brushes.Black, r, StringFormat.GenericTypographic);
    13
    14 f.Dispose();
    15 }
  • 相关阅读:
    最短路径:HDU2006-一个人的旅行(多个起点,多个终点)
    最短路径(最基础,经典的模板和思想):HDU-2544最短路
    数学算法:poweroj1026-丑数(根据固定倍数得到从小到大的序列)
    动态规划:ZOJ1074-最大和子矩阵 DP(最长子序列的升级版)
    数论:HDU1066-Last non-zero Digit in N!
    容斥原理:HDU-4135Co-prime
    数学算法:求一个数的质因子
    动态规划(入门,滚动数组,记录的都是状态):SWUSTACM-1010 魔兽争霸之最后的反击
    动态规划(入门):各种数字三角形
    动态规划:HDU2571-命运
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2046322.html
Copyright © 2011-2022 走看看