當前位置: 首頁>>代碼示例>>C#>>正文


C# FontDialog類代碼示例

本文整理匯總了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;
    }
 }
開發者ID:.NET開發者,項目名稱:System.Windows.Forms,代碼行數:13,代碼來源:FontDialog

示例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;
     }
}
開發者ID:C#程序員,項目名稱:System.Windows.Forms,代碼行數:67,代碼來源:FontDialog


注:本文中的System.Windows.Forms.FontDialog類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。