📄 genericfonts.cs
字号:
x = 10;
g.DrawString(str, font, brText, x, y);
SizeF sizeString = g.MeasureString(str, font);
x += sizeString.Width;
// Draw with Sans Serif regular m_ptSize pt font.
str = "Regular (" + font.Name + ")";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create Sans Serif italic m_ptSize pt font.
font = new Font(FontFamily.GenericSansSerif, m_ptSize,
FontStyle.Italic);
str = "Italic";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create Sans Serif bold m_ptSize pt font.
font = new Font(FontFamily.GenericSansSerif, m_ptSize,
FontStyle.Bold);
str = "Bold";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create Sans Serif strikeout m_ptSize pt font.
font = new Font(FontFamily.GenericSansSerif, m_ptSize,
FontStyle.Strikeout);
str = "Strikeout";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create Sans Serif underline m_ptSize pt font.
font = new Font(FontFamily.GenericSansSerif, m_ptSize,
FontStyle.Underline);
str = "Underline";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Add spacing between text blocks.
y += sizeString.Height / 2;
}
private void
DisplaySerifFont(Graphics g, ref float x, ref float y)
{
// Create brush for standard text color.
Brush brText = new SolidBrush(SystemColors.WindowText);
// Create a serif regular m_ptSize point font.
Font font = new Font(FontFamily.GenericSerif, m_ptSize,
FontStyle.Regular);
string str = "Serif: ";
x = 10;
g.DrawString(str, font, brText, x, y);
SizeF sizeString = g.MeasureString(str, font);
x += sizeString.Width;
// Draw with the serif regular m_ptSize point font.
str = "Regular (" + font.Name + ")";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create a serif italic m_ptSize point font.
font = new Font(FontFamily.GenericSerif, m_ptSize,
FontStyle.Italic);
str = "Italic";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create a serif bold m_ptSize point font.
font = new Font(FontFamily.GenericSerif, m_ptSize,
FontStyle.Bold);
str = "Bold";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create a serif strikeout m_ptSize point font.
font = new Font(FontFamily.GenericSerif, m_ptSize,
FontStyle.Strikeout);
str = "Strikeout";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Create a serif underline m_ptSize point font.
font = new Font(FontFamily.GenericSerif, m_ptSize,
FontStyle.Underline);
str = "Underline";
g.DrawString(str, font, brText, x, y);
sizeString = g.MeasureString(str, font);
y += sizeString.Height;
font.Dispose();
// Add spacing between text blocks.
y += sizeString.Height / 2;
}
private void
FormMain_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
float x = 10;
float y = 10;
//
// GenericMonospace Font Styles
//
if (mitemFontMono.Checked)
{
DisplayMonoFont(g, ref x, ref y);
}
//
// GenericSansSerif Font Styles
//
if (mitemFontSans.Checked)
{
DisplaySansSerifFont(g, ref x, ref y);
}
//
// GenericSerif Font Styles
//
if (mitemFontSerif.Checked)
{
DisplaySerifFont(g, ref x, ref y);
}
}
private void UncheckAllSizes()
{
mitemSize8.Checked = false;
mitemSize10.Checked = false;
mitemSize12.Checked = false;
mitemSize14.Checked = false;
mitemSize16.Checked = false;
mitemSize18.Checked = false;
mitemSize24.Checked = false;
}
private void mitemSize8_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize8.Checked = true;
Text = "GenericFonts - 8 pt.";
m_ptSize = 8;
Invalidate();
}
private void mitemSize10_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize10.Checked = true;
Text = "GenericFonts - 10 pt.";
m_ptSize = 10;
Invalidate();
}
private void mitemSize12_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize12.Checked = true;
Text = "GenericFonts - 12 pt.";
m_ptSize = 12;
Invalidate();
}
private void mitemSize14_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize14.Checked = true;
Text = "GenericFonts - 14 pt.";
m_ptSize = 14;
Invalidate();
}
private void mitemSize16_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize16.Checked = true;
Text = "GenericFonts - 16 pt.";
m_ptSize = 16;
Invalidate();
}
private void mitemSize18_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize18.Checked = true;
Text = "GenericFonts - 18 pt.";
m_ptSize = 18;
Invalidate();
}
private void mitemSize24_Click(object sender, System.EventArgs e)
{
UncheckAllSizes();
mitemSize24.Checked = true;
Text = "GenericFonts - 24 pt.";
m_ptSize = 24;
Invalidate();
}
private void mitemFontMono_Click(object sender, System.EventArgs e)
{
mitemFontMono.Checked = !mitemFontMono.Checked;
Invalidate();
}
private void mitemFontSans_Click(object sender, System.EventArgs e)
{
mitemFontSans.Checked = !mitemFontSans.Checked;
Invalidate();
}
private void mitemFontSerif_Click(object sender, System.EventArgs e)
{
mitemFontSerif.Checked = !mitemFontSerif.Checked;
Invalidate();
}
} // class
} // namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -