本文整理汇总了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);
}
}