We help IT Professionals succeed at work.

How to set the FontDialog-component to a certain fontname/size by pressing on a button.

Peter Kiers
Peter Kiers asked
on
Hi Experts,

I am programming in VS2010 and I am using C#.
On my dialog-form I have a Button, editbox(readonly) and
a FontDialog-component.

A user can press the button and the FontDialog-window
appears the user can then set his fontname, size etc...
After closting the fontdialog-window, the choosen Font-
Name and size appears in the editbox.

        private void btnFontType_Click(object sender, EventArgs e)
        {
            if (fontDialog1.ShowDialog() == DialogResult.OK)
            {
                txtFont.Text = Convert.ToInt32(this.fontDialog1.Font.SizeInPoints).ToString() + " pt. " +
                fontDialog1.Font.Name;
            }
        }

Open in new window


What I would like is to create a button called Default, that sets the fontdialog to
the default fontname: Microsoft Sans Serif and default fontsize: 8.

How can I do that?

Greetings,

Peter Kiers
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2015
Commented:
FontDialog1.Font = New Font("Microsoft Sans Serif", 8)
            FontDialog1.ShowDialog()
Peter KiersOperator

Author

Commented:
Thanks. Peter

Explore More ContentExplore courses, solutions, and other research materials related to this topic.