This topic has not yet been rated - Rate this topic

FontDialog.FontMustExist Property

Gets or sets a value indicating whether the dialog box specifies an error condition if the user attempts to select a font or style that does not exist.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration
Public Property FontMustExist As Boolean

Property Value

Type: System.Boolean
true if the dialog box specifies an error condition when the user tries to select a font or style that does not exist; otherwise, false. The default is false.

The following code example demonstrates using the MinSize, MaxSize, ShowEffects and FontMustExist members and handling the Apply event. To run this example paste the following code in a form containing a FontDialog named FontDialog1 and a Button named Button1.

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Set FontMustExist to true, which causes message box error 
    ' if the user enters a font that does not exist. 
    FontDialog1.FontMustExist = True 

    ' Set a minimum and maximum size to be 
    ' shown in the FontDialog.
    FontDialog1.MaxSize = 32
    FontDialog1.MinSize = 18

    ' Show the Apply button in the dialog.
    FontDialog1.ShowApply = True 

    ' Do not show effects such as Underline 
    ' and Bold.
    FontDialog1.ShowEffects = False 

    ' Save the existing font. 
    Dim oldFont As System.Drawing.Font = Me.Font

    ' Show the dialog and save the result. 
    Dim result As DialogResult = FontDialog1.ShowDialog()

    ' If The OK button in the Font dialog box is clicked,  
    ' set all the controls' fonts to the chosen font by 
    ' calling the FontDialog1_Apply method. 
    If result = DialogResult.OK Then
        FontDialog1_Apply(Me.Button1, New System.EventArgs)

        ' If the Cancel button is clicked, set the controls' 
        ' fonts back to the original font. 
    ElseIf (result = DialogResult.Cancel) Then 
        Dim containedControl As Control
        For Each containedControl In Me.Controls
            containedControl.Font = oldFont
        Next 

    End If 
End Sub 

' Handle the Apply event by setting all controls' fonts to  
' the chosen font.  
Private Sub FontDialog1_Apply(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles FontDialog1.Apply

    Me.Font = FontDialog1.Font
    Dim containedControl As Control
    For Each containedControl In Me.Controls
        containedControl.Font = FontDialog1.Font
    Next 
End Sub
FontDialog.MaxSize, FontDialog.ShowEffects and FontDialog.FontMustExist members and handling the Apply event. To run this example paste the following code in a form 

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.