Link to home
Start Free TrialLog in
Avatar of Peter Kiers
Peter KiersFlag for Netherlands

asked on

Display the chosen fontname en fontsize of a fontdialog in a textbox, part2

Hi,

I have a button, a textbox and a fontdialog on my form.
When I click on the button the fontdialog appears
Where I can choose the fontname and size

What would is in the textbox, the size of the font
and the name of the font that I have chosen
in the fontdialog. How can I do that?

I have put an image of outlook so you see how I
want it to be.

Who knows the answer and is willing to help me?

Greetings, Peter Kiers
Example1.jpg
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Try this:

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

Open in new window


Hope that helps.
Avatar of Peter Kiers

ASKER

I am going to try your code now

Peter
It works. But when I choose Comic Sans MS and size 10 I get:

9,75 pt. Comic Sans MS

How come I get 9,75 and not 10.

Peter
ASKER CERTIFIED SOLUTION
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great. 500 points are comming to you...

Greetings, Peter Kiers