📄 sample5.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(40, 32);
this.panel1.Name = "panel1";
this.panel1.TabIndex = 0;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void panel1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
FontFamily[] testFF = FontFamily.GetFamilies (e.Graphics);
//使用GetFamilies方法获取包含指定的图形上下文
//可用的所有 FontFamily 对象的数组
Font testF;
string str;
float space = 0;
for(int i=0;i<8 ;i++)
{
FontFamily family=testFF[i];
testF = new Font(family,10);
str = "这是"+family.Name+"的family。";
e.Graphics.DrawString(str,testF,Brushes.Black,new PointF(0, space));
space += testF.Height;
}
testF=new Font("Arial",10);
FontFamily testFF1 = new FontFamily("Arial");
FontFamily testFF2 = new FontFamily("Times New Roman");
bool b = testFF1.Equals(testFF2);
e.Graphics.DrawString("testFF1值:"+testFF1.ToString(),testF,Brushes.Black,new PointF(0,space));
space+=testF.Height;
e.Graphics.DrawString("testFF2值:"+testFF2.ToString(),testF,Brushes.Black,new PointF(0,space));
space+=testF.Height;
e.Graphics.DrawString("上述两个对象是否相等?"+b,testF,Brushes.Black,new PointF(0,space));
//使用Equals方法判断指定的对象是否是 FontFamily 对象以及是否与此 FontFamily 对象相同
space+=testF.Height;
int cA = testFF2.GetCellAscent (FontStyle.Regular);
//使用GetCellAscent方法获取指定的 FontStyle 枚举的此FontFamily 对象的单元格上升
e.Graphics.DrawString("testFF2.GetCellAscent()返回值:" +
cA.ToString() + "。",testF,Brushes.Black,
new PointF(0,space));
space+=testF.Height;
int cD = testFF2.GetCellDescent (FontStyle.Regular);
//使用GetCellDescent方法获取指定的 FontStyle 枚举的此
//FontFamily 对象的单元格下降
e.Graphics.DrawString("testFF2.GetCellDescent()返回值:" +
cD.ToString() + "。",testF,Brushes.Black,
new PointF(0,space));
space+=testF.Height;
int em = testFF2.GetEmHeight (FontStyle.Regular);
//使用GetEmHeight方法获取指定样式的 em 方形的高度
e.Graphics.DrawString("testFF2.GetEmHeight()返回值:" +
em.ToString() + "。",estF,Brushes.Black,new PointF(0,space));
space+=testF.Height;
int lS = testFF2.GetLineSpacing(FontStyle.Regular);
//使用GetLineSpacing方法两行相邻文本之间的距离
e.Graphics.DrawString("lineSpacing值:" + lS.ToString(),testF,
Brushes.Black,new PointF(0,space));
space+=testF.Height;
//使用IsStyleAvailable方法判断指定的 FontStyle 枚举是否
//可用
if(testFF2.IsStyleAvailable(FontStyle.Italic))
{
e.Graphics.DrawString(testFF2.Name + "斜有效。",testF,
Brushes.Black,new PointF(0,space));
space+=testF.Height;
}
str=testFF2.GetName(0);
//使用GetName方法获取指定的语言返回此 FontFamily 对象的名称
e.Graphics.DrawString("testFF2对象的family名是" + str,testF,
Brushes.Black,new PointF(0,space));
space+=testF.Height;
e.Graphics.DrawString("testFF2对象的字符串表示形式:" + testFF2.ToString(),testF,Brushes.Black,
new PointF(0,space));
//使用ToString方法获取对象的字符串表示形式
for(int i=0;i<testFF.Length;i++)
testFF[i].Dispose();
//使用Dispose方法释放资源
testFF1.Dispose();
testFF2.Dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -