您的位置:首页 > 编程语言 > C#

C# 在窗体中绘制字符串

2017-02-28 21:57 369 查看


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 绘制字体
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.TranslateTransform(AutoScrollPosition.X,AutoScrollPosition.Y);
Point position = new Point(0, 8);
foreach(FontFamily f in FontFamily.Families)//电脑上所有的字体
{
if(f.IsStyleAvailable(FontStyle.Regular))//符合字体普通格式的字体(比如加粗,斜线)
{
Font font=new Font(f.Name,10);
g.DrawString(f.Name, font, Brushes.Red, position);//第一个参数是 在窗体显示的字符串,第二个是此字符串的字体,第三个是颜色,第四个是输出的起始位置
position.Y += font.Height + 5;                    //每输出一个字体后,输出位置向下移
font.Dispose();
}
}
this.AutoScrollMinSize = new Size(350, position.Y + 50);//滚动框
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: