Let us look at a simple C# Windows Forms FontDialog example.
Example 1: FontDialog
This example will comprise the following files:
FontDialog.cs
Step 1: Create Project
- The first step is to create a C# Project.
- Go to
FILE-->New-->Project
to create a new project.
Step 2: Write Code
Write Code as follows:
*(a). FontDialog.cs
Create a file named FontDialog.cs
Here is the full code
using System;
using System.Windows.Forms;
namespace FolderBrowserDialogExample {
class Form1 : Form {
// The main entry point for the application.
public static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form1());
}
public Form1() {
label.Text = "The quick brown fox jumps over the lazy dog.n" +
"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.n" +
"0123456789+-*/%~^&|=<>≤≥±÷≠{{[()]}},;:.?¿!¡n" +
"àçéèêëïî@@°_#§$ù£€æœøπµ©®∞\"'n" +
"u0400u0401u0402u0403u0404u0405u0406u0407u0408u0409u040au040bu040cu040du040eu040fn" +
"u0410u0411u0412u0413u0414u0415u0416u0417u0418u0419u041au041bu041cu041du041eu041fn" +
"u4ea0u4ea1u4ea2u4ea3u4ea4u4ea5u4ea6u4ea7u4ea8u4ea9u4eaau4eabu4eacu4eadu4eaeu4eafn" +
"u4eb0u4eb1u4eb2u4eb3u4eb4u4eb5u4eb6u4eb7u4eb8u4eb9u4ebau4ebbu4ebcu4ebdu4ebeu4ebfn" +
"U0001F428";
label.Font = new System.Drawing.Font("Segoe UI Emoji", 8);
label.Location = new System.Drawing.Point(10, 50);
label.Size = new System.Drawing.Size(380, 340);
button.Text = "Font...";
button.Location = new System.Drawing.Point(10, 10);
button.Click += delegate (object sender, EventArgs e) {
FontDialog fontDialog = new FontDialog();
fontDialog.ShowColor = true;
fontDialog.Font = label.Font;
fontDialog.Color = label.ForeColor;
if (fontDialog.ShowDialog() == DialogResult.OK) {
label.Font = fontDialog.Font;
label.ForeColor = fontDialog.Color;
}
};
Text = "Font Example";
ClientSize = new System.Drawing.Size(400, 400);
Controls.AddRange(new Control[] { button, label });
}
private Button button = new Button();
private Label label = new Label();
}
}
Run
Simply copy the source code into your C# Project,Build and Run. Alternatively download the code using the links provided below, then open the .csproj
project, build and run.
Reference
Download the code using the below links:
Number | Link |
---|---|
1. | Download Example |
2. | Follow code author |