本文整理汇总了C#中System.Drawing.Font类的典型用法代码示例。如果您正苦于以下问题:C# Font类的具体用法?C# Font怎么用?C# Font使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Font类属于System.Drawing命名空间,在下文中一共展示了Font类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: new Font(String fontName, int size)
//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class FormPaintEvent : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public FormPaintEvent()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Text = "Form1";
}
[STAThread]
static void Main()
{
Application.Run(new FormPaintEvent());
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawString("String...", new Font("Times New Roman", 20), new SolidBrush(Color.Black), 40, 10);
}
}
示例3: 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);
}
}