-3

Is there a dialog window for selecting a font in WPF? How to put the selected font to TextBox?

0

1 Answer 1

0

Yes its called FontDialog. Below is a sample code for opening a fontdialogbox with a button click.

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;
            }
        }
    }
}
1
  • 1
    Its in Windows Forms. I asked about wpf. In wpf I didnt find class "FontDialog"
    – Yaroslav
    Jan 3, 2019 at 20:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.