WPF。是否存在用于在WPF中选择字体的对话框窗口?

时间:2019-01-03 20:18:47

标签: c# wpf textbox

是否存在用于在WPF中选择字体的对话框窗口?如何将所选字体放入TextBox?

1 个答案:

答案 0 :(得分:0)

是的,它叫做FontDialog。以下是通过单击按钮打开fontdialogbox的示例代码。

using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Show the dialog.
            DialogResult result = fontDialog1.ShowDialog();
            // See if OK was pressed.
            if (result == DialogResult.OK)
            {
                // Get Font.
                Font font = fontDialog1.Font;
                // Set TextBox properties.
                this.textBox1.Text = string.Format("Font: {0}", font.Name);
                this.textBox1.Font = font;
            }
        }
    }
}