?? mainform.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()
{
// 讀取系統(tǒng)中安裝的字體,羅列到下拉框中
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;
// 創(chuàng)建字體
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();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -