本文整理汇总了C#中System.Windows.Forms.FontDialog类的典型用法代码示例。如果您正苦于以下问题:C# FontDialog类的具体用法?C# FontDialog怎么用?C# FontDialog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FontDialog类属于System.Windows.Forms命名空间,在下文中一共展示了FontDialog类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: button1_Click
private void button1_Click(object sender, System.EventArgs e)
{
fontDialog1.ShowColor = true;
fontDialog1.Font = textBox1.Font;
fontDialog1.Color = textBox1.ForeColor;
if(fontDialog1.ShowDialog() != DialogResult.Cancel )
{
textBox1.Font = fontDialog1.Font ;
textBox1.ForeColor = fontDialog1.Color;
}
}
示例2: new FontDialog()
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class FontMenuForm: Form
{
protected string strText = "Sample Text";
protected Font font = new Font("Times New Roman", 24, FontStyle.Italic);
public static void Main()
{
Application.Run(new FontMenuForm());
}
public FontMenuForm()
{
ResizeRedraw = true;
Menu = new MainMenu();
Menu.MenuItems.Add("&Font!", new EventHandler(MenuFontOnClick));
}
void MenuFontOnClick(object obj, EventArgs ea)
{
FontDialog dlg = new FontDialog();
dlg.Font = font;
if (dlg.ShowDialog() == DialogResult.OK)
{
font = dlg.Font;
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
{
SizeF sizef = grfx.MeasureString(strText, font);
Brush brush = new SolidBrush(clr);
grfx.DrawString(strText, font, brush, (cx - sizef.Width) / 2,
(cy - sizef.Height) / 2);
}
public float GetAscent(Graphics grfx, Font font)
{
return font.GetHeight(grfx) *
font.FontFamily.GetCellAscent(font.Style) /
font.FontFamily.GetLineSpacing(font.Style);
}
public float GetDescent(Graphics grfx, Font font)
{
return font.GetHeight(grfx) *
font.FontFamily.GetCellDescent(font.Style) /
font.FontFamily.GetLineSpacing(font.Style);
}
public float PointsToPageUnits(Graphics grfx, Font font)
{
float fFontSize;
if (grfx.PageUnit == GraphicsUnit.Display)
fFontSize = 100 * font.SizeInPoints / 72;
else
fFontSize = grfx.DpiX * font.SizeInPoints / 72;
return fFontSize;
}
}