本文整理匯總了C#中System.Drawing.Font.SizeInPoints屬性的典型用法代碼示例。如果您正苦於以下問題:C# Font.SizeInPoints屬性的具體用法?C# Font.SizeInPoints怎麽用?C# Font.SizeInPoints使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Drawing.Font
的用法示例。
在下文中一共展示了Font.SizeInPoints屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ComboBox1_SelectedIndexChanged
private void ComboBox1_SelectedIndexChanged(System.Object sender,
System.EventArgs e)
{
// Cast the sender object back to a ComboBox.
ComboBox ComboBox1 = (ComboBox) sender;
// Retrieve the selected item.
string selectedString = (string) ComboBox1.SelectedItem;
// Convert it to lowercase.
selectedString = selectedString.ToLower();
// Declare the current size.
float currentSize;
// Switch on the selected item.
switch(selectedString)
{
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
case "bigger":
currentSize = Label1.Font.Size;
currentSize += 2.0F;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style, Label1.Font.Unit);
// If Smaller is selected, get the current size, in points,
// and decrease it by 1. Reset the font with the new size
// in points.
break;
case "smaller":
currentSize = Label1.Font.SizeInPoints;
currentSize -= 1;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style);
break;
}
}
示例2: Main
//引入命名空間
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);
}
}