Font: SizeInPoints : Font « GUI Windows Form « C# / C Sharp






Font: SizeInPoints

 

using System;
using System.Drawing;
using System.Windows.Forms;
   
class HowdyWorld: Form
{
     public static void Main()
     {
          Application.Run(new HowdyWorld());
     }
     public HowdyWorld()
     {
          ResizeRedraw = true; 
          MinimumSize = SystemInformation.MinimumWindowSize + new Size(0,1);
          
     }
     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)
     {
          Font  font   = new Font("Times New Roman", 10, FontStyle.Italic);
          SizeF sizef  = grfx.MeasureString(Text, font);
          float fScale = Math.Min(cx / sizef.Width, cy / sizef.Height);
   
          font = new Font(font.Name, fScale * font.SizeInPoints, font.Style);
          sizef = grfx.MeasureString(Text, font);
   
          grfx.DrawString(Text, font, new SolidBrush(clr), 
                          (cx  - sizef.Width ) / 2, (cy - sizef.Height) / 2);
     }
}

 








Related examples in the same category

1.All font properties
2.new Font("Times New Roman", 10, FontStyle.Italic)
3.new Font(strFont, fSize)
4.new Font(fontRegular, FontStyle.Italic);
5.Text on Baseline
6.Font with different size
7.Font: GetHeight
8.System Fonts: Icon Title FontSystem Fonts: Icon Title Font
9.Load all system installed fontsLoad all system installed fonts
10.Timer based animation for fontTimer based animation for font
11.Get all system installed fontGet all system installed font
12.Font listFont list