C#中的字体和字体系列
C#中的字体和字体系列
2009-05-22 16:17
1.字体系列:System.Drawing.FontFamily,指文本的可视化风格,如“宋体”等;
2.字体:System.Drawing.Font,包含了字体系列、文本大小、文本样式等信息。
实例:打印系统上安装的字体
TestFonts:
Form1.cs:
view plaincopy to clipboardprint?
1.using System;
2.using System.Collections.Generic;
3.using System.ComponentModel;
4.using System.Data;
5.using System.Drawing;
6.using System.Text;
7.using System.Windows.Forms;
8.using System.Drawing.Text;
9.
10.namespace TestFonts
11.{
12.public partial class Form1 : Form
13.{
14.//文本间距
15.private const int margin = 10;
16.
17.public Form1()
18.{
字体app免费下载19.InitializeComponent();
20.this.AutoScrollMinSize = new Size(200, 3000);
21.this.BackColor = Color.White;
22.}
23.
24.protected override void OnPaint(PaintEventArgs e)
25.{
26.base.OnPaint(e);
27.Graphics dc = e.Graphics;
28.
29.int verticalCoordinate = margin;
30.Point topLeftCorner;
31.//取得系统上安装的所有字体
32.InstalledFontCollection insFont = new InstalledFontCollection();
33.FontFamily[] families = insFont.Families;
34.dc.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
35.
36.//遍历字体系列
37.foreach (FontFamily family in families)
38.{
39.//只显示支持普通文本风格的字体系列
40.if (family.IsStyleAvailable(FontStyle.Regular))
41.{
42.Font f = new Font(family.Name, 10);
43.topLeftCorner = new Point(margin, verticalCoordinate);
44.//换行
45.verticalCoordinate += f.Height;
46.dc.DrawString(family.Name, f, Brushes.Black, topLeftCorner);
47.f.Dispose();
48.}
49.}
50.}
51.}
52.} using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Text;
namespace TestFonts
{
public partial class Form1 : Form
{
//文本间距
private const int margin = 10;
public Form1()
{
InitializeComponent();
this.AutoScrollMinSize = new Size(200, 3000);
this.BackColor = Color.White;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics dc = e.Graphics;
int verticalCoordinate = margin;
Point topLeftCorner;
//取得系统上安装的所有字体
InstalledFontCollection insFont = new InstalledFontCollection();
FontFamily[] families = insFont.Families;
dc.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
//遍历字体系列
foreach (FontFamily family in families)
{
//只显示支持普通文本风格的字体系列
if (family.IsStyleAvailable(FontStyle.Regular))
{
Font f = new Font(family.Name, 10);
topLeftCorner = new Point(margin, verticalCoordinate);
//换行
verticalCoordinate += f.Height;
dc.DrawString(family.Name, f, Brushes.Black, topLeftCorner);
f.Dispose();
}
}
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论