Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-02
5
Medium Priority
?
394 Views
Last Modified: 2013-12-17
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
0
Comment
Question by:peterkiers
  • 3
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 36472616
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
 
LVL 1

Author Comment

by:peterkiers
ID: 36472664
I am going to try your code now

Peter
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36472725
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
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 36472745
Try this:

this.textBox1.Text = Convert.ToInt32(this.fontDialog1.Font.SizeInPoints).ToString() + " pt. " + this.fontDialog1.Font.Name;
0
 
LVL 1

Author Comment

by:peterkiers
ID: 36472775
Great. 500 points are comming to you...

Greetings, Peter Kiers
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question