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
LVL 1
peterkiersAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Luis PérezConnect With a Mentor Software Architect in .NetCommented:
Try this:

this.textBox1.Text = Convert.ToInt32(this.fontDialog1.Font.SizeInPoints).ToString() + " pt. " + this.fontDialog1.Font.Name;
0
 
Luis PérezSoftware Architect in .NetCommented:
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.
0
 
peterkiersAuthor Commented:
I am going to try your code now

Peter
0
 
peterkiersAuthor Commented:
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
0
 
peterkiersAuthor Commented:
Great. 500 points are comming to you...

Greetings, Peter Kiers
0
All Courses

From novice to tech pro — start learning today.