using System;
using System.Drawing;
using System.Windows.Forms;
class TwentyFourPointPrinterFonts: Form
{
public static void Main()
{
Application.Run(new TwentyFourPointPrinterFonts());
}
public TwentyFourPointPrinterFonts()
{
Text = "Twenty-Four Point Printer Fonts";
ResizeRedraw = true;
}
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)
{
Brush brush = new SolidBrush(clr);
float y = 0;
Font font;
string strFamily = "Times New Roman";
font = new Font(strFamily, 24);
grfx.DrawString("No GraphicsUnit, 24 points", font, brush, 0, y);
y += font.GetHeight(grfx);
font = new Font(strFamily, 24, GraphicsUnit.Point);
grfx.DrawString("GraphicsUnit.Point, 24 units", font, brush, 0, y);
y += font.GetHeight(grfx);
font = new Font(strFamily, 1/ 3f, GraphicsUnit.Inch);
grfx.DrawString("GraphicsUnit.Inch, 1/3 units", font, brush, 0, y);
y += font.GetHeight(grfx);
font = new Font(strFamily, 25.4f / 3, GraphicsUnit.Millimeter);
grfx.DrawString("GraphicsUnit.Millimeter, 25.4/3 units",
font, brush, 0, y);
y += font.GetHeight(grfx);
font = new Font(strFamily, 100, GraphicsUnit.Document);
grfx.DrawString("GraphicsUnit.Document, 100 units",
font, brush, 0, y);
y += font.GetHeight(grfx);
font = new Font(strFamily, 100f / 3, GraphicsUnit.Pixel);
grfx.DrawString("GraphicsUnit.Pixel, " + 100f / 3 + " units",
font, brush, 0, y);
y += font.GetHeight(grfx);
font = new Font(strFamily, 100f / 3, GraphicsUnit.World);
grfx.DrawString("GraphicsUnit.World, " + 100f / 3 + " units",
font, brush, 0, y);
}
}
Software Development
software development notes, main category for Cs, Java, and other programming experiences.
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);
}
}
Text on Baseline
using System;
using System.Drawing;
using System.Windows.Forms;
class TextOnBaseline: Form{
public static void Main() {
Application.Run(new TextOnBaseline());
}
public TextOnBaseline() {
ResizeRedraw = true;
}
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) {
float yBaseline = cy / 2;
Pen pen = new Pen(clr);
grfx.DrawLine(pen, 0, yBaseline, cx, yBaseline);
Font font = new Font("Times New Roman", 144);
float cyLineSpace = font.GetHeight(grfx);
int iCellSpace = font.FontFamily.GetLineSpacing(font.Style);
int iCellAscent = font.FontFamily.GetCellAscent(font.Style);
float cyAscent = cyLineSpace * iCellAscent / iCellSpace;
grfx.DrawString("Baseline", font, new SolidBrush(clr),
0, yBaseline - cyAscent);
}
}
new Font(fontRegular, FontStyle.Italic);
using System;
using System.Drawing;
using System.Windows.Forms;
class BoldAndItalic : Form {
public static void Main() {
Application.Run(new BoldAndItalic());
}
public BoldAndItalic() {
Text = "Bold and Italic Text";
ResizeRedraw = true;
}
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) {
float x = 0;
float y = 0;
grfx.DrawString("text", new Font(this.Font, FontStyle.Bold), new SolidBrush(Color.AliceBlue), x, y);
}
}
new Font(strFont, fSize)
using System;
using System.Drawing;
using System.Windows.Forms;
class FontSizes: Form
{
public static void Main()
{
Application.Run(new FontSizes());
}
public FontSizes()
{
Text = “Font Sizes”;
ResizeRedraw = true;
}
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)
{
string strFont = “Times New Roman”;
Brush brush = new SolidBrush(clr);
float y = 0;
for (float fSize = 6; fSize <= 12; fSize += 0.25f) { Font font = new Font(strFont, fSize); grfx.DrawString(strFont + " in " + fSize + " points", font, brush, 0, y); } } } [/csharp]
new Font(“Times New Roman”, 10, FontStyle.Italic)
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);
grfx.DrawString(Text, font, new SolidBrush(clr),
(cx - sizef.Width ) / 2, (cy - sizef.Height) / 2);
}
}
All font properties
using System;
using System.Drawing;
using System.Windows.Forms;
class AllAboutFont: Form
{
public static void Main()
{
Application.Run(new AllAboutFont());
}
public AllAboutFont()
{
ResizeRedraw = true;
}
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)
{
grfx.DrawString(
"Name: " + Font.Name + "
" +
"FontFamily: " + Font.FontFamily + "
" +
"FontStyle: " + Font.Style + "
" +
"Bold: " + Font.Bold + "
" +
"Italic: " + Font.Italic + "
" +
"Underline: " + Font.Underline + "
" +
"Strikeout: " + Font.Strikeout + "
" +
"Size: " + Font.Size + "
" +
"GraphicsUnit: " + Font.Unit + "
" +
"SizeInPoints: " + Font.SizeInPoints + "
" +
"Height: " + Font.Height + "
" +
"GdiCharSet: " + Font.GdiCharSet + "
" +
"GdiVerticalFont : " + Font.GdiVerticalFont + "
" +
"GetHeight(): " + Font.GetHeight() + "
" +
"GetHeight(grfx): " + Font.GetHeight(grfx) + "
" +
"GetHeight(100 DPI): " + Font.GetHeight(100),
Font, new SolidBrush(clr), Point.Empty);
}
}