C# 在窗体中绘制字符串

来源:互联网 发布:王天一用软件作弊 编辑:程序博客网 时间:2024/05/17 04:09

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);//滚动框        }            }}


0 0
原创粉丝点击