The great thing about Font dialogs is that they return Font and Color objects, saving you the trouble of configuring those objects from scratch. This is handy because you can assign these objects directly to the properties of controls that can use them.
Here's an example, called FontDialog on the CD-ROM. In this case, I'll set the font used in a rich text box simply by assigning the Font and Color properties of a Font dialog to the Font and ForeColor properties of the rich text box, unless the user has clicked the Cancel button in that dialog:
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click If FontDialog1.ShowDialog <> DialogResult.Cancel Then RichTextBox1.Font = FontDialog1.Font RichTextBox1.ForeColor = FontDialog1.Color End If End Sub
You can see the Font dialog that this example creates in Figure 9.5. In the FontDialog example, you click a button labeled "Select font" to display this dialog, and when you dismiss it, the new font is assigned to the rich text box, as you see in Figure 9.19.