⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 WindowsMobile平台应用开发一书的源码
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Text;
using System.Windows.Forms;

namespace UsingSystemFont
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();

			m_addSystemFont();

			m_cmbFamilies.SelectedIndex = 0;
			m_cmbSize.SelectedIndex = 5;
		}

		private void m_addSystemFont()
		{
			// 读取系统中安装的字体,罗列到下拉框中
			using(InstalledFontCollection fonts = new InstalledFontCollection())
			{
				foreach(FontFamily ff in fonts.Families)
				{
					m_cmbFamilies.Items.Add(ff.Name);
				}
			}
		}

		private void MainForm_Paint(object sender, PaintEventArgs e)
		{
			InstalledFontCollection fonts = new InstalledFontCollection();
			FontFamily family = null;
			Font f = null;
			float emSize = 0.0f;
			FontStyle style = FontStyle.Regular;
			SolidBrush b = new SolidBrush(Color.Blue);

			// 确定所使用的字体族
			family = fonts.Families[m_cmbFamilies.SelectedIndex];

			// 确定字体的大小
			emSize = Single.Parse(m_cmbSize.Text);

			// 确定字体的样式
			if(m_chkBold.Checked)
				style |= FontStyle.Bold;
			if(m_chkItalic.Checked)
				style |= FontStyle.Italic;
			if(m_chkStrikeout.Checked)
				style |= FontStyle.Strikeout;
			if(m_chkUnderline.Checked)
				style |= FontStyle.Underline;

			// 创建字体
			f = new Font(family, emSize, style);

			// 绘制文本
			e.Graphics.DrawString(m_txtText.Text, f, b, 10, m_chkStrikeout.Bottom + 10);

			// 释放资源
			fonts.Dispose();
			f.Dispose();
			b.Dispose();
		}

		private void m_onNeedRedraw(object sender, EventArgs e)
		{
			this.Invalidate();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -