C# 自定義『微軟正黑體(Microsoft JhengHei UI)』字型大小 12~20 簡單測試範例
C# 自定義『微軟正黑體(Microsoft JhengHei UI)』字型大小 12~20 簡單測試範例
code
namespace WinFormsCustomizeFont { public partial class Form1 : Form { Font Font12 = new System.Drawing.Font("Microsoft JhengHei UI", 12, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); Font Font14 = new System.Drawing.Font("Microsoft JhengHei UI", 14, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); Font Font16 = new System.Drawing.Font("Microsoft JhengHei UI", 16, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); Font Font18 = new System.Drawing.Font("Microsoft JhengHei UI", 18, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); Font Font20 = new System.Drawing.Font("Microsoft JhengHei UI", 20, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { textBox1.Font = Font12; } private void button2_Click(object sender, EventArgs e) { textBox1.Font = Font14; } private void button3_Click(object sender, EventArgs e) { textBox1.Font = Font16; } private void button4_Click(object sender, EventArgs e) { textBox1.Font = Font18; } private void button5_Click(object sender, EventArgs e) { textBox1.Font = Font20; } } }
namespace WinFormsCustomizeFont { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.button2 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.button5 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(41, 185); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(124, 59); this.button1.TabIndex = 0; this.button1.Text = "12"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(38, 8); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(697, 27); this.textBox1.TabIndex = 1; this.textBox1.Text = "小廖"; // // button2 // this.button2.Location = new System.Drawing.Point(171, 185); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(124, 59); this.button2.TabIndex = 2; this.button2.Text = "14"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button3 // this.button3.Location = new System.Drawing.Point(301, 185); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(124, 59); this.button3.TabIndex = 3; this.button3.Text = "16"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button4 // this.button4.Location = new System.Drawing.Point(431, 185); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(124, 59); this.button4.TabIndex = 4; this.button4.Text = "18"; this.button4.UseVisualStyleBackColor = true; this.button4.Click += new System.EventHandler(this.button4_Click); // // button5 // this.button5.Location = new System.Drawing.Point(561, 185); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(124, 59); this.button5.TabIndex = 5; this.button5.Text = "20"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 19F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(968, 611); this.Controls.Add(this.button5); this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.textBox1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private Button button1; private TextBox textBox1; private Button button2; private Button button3; private Button button4; private Button button5; } }