Wednesday, April 11, 2012

FontDialog box control in C# (Windows Forms)

Author : Prakash Pradeep Gopu
Font dialog box represents a common dialog box that displays a list of fonts that are currently installed on the system. The Font dialog box lets the user choose attributes for a logical font, such as font family and associated font style, point size, effects , and a script .
The following C# program invites a Font Dialog Box and retrieve the selected Font Name and Font Size.
1)Create a Create  form in the windows application
2)Drag the font dialog box control on to your form and place button on to the same form.
3)Copy the following code in the button Click event.

private void button1_Click(object sender, EventArgs e)
            FontDialog dlg = new FontDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
                string fontName;
                float fontSize;
                fontName = dlg.Font.Name;
                fontSize = dlg.Font.Size;
                MessageBox.Show(fontName + "    " + fontSize);

Output :

No comments:

Post a Comment