次の方法で共有


FontDialog.MaxSize プロパティ

ユーザーが選択できるポイント サイズの最大値を取得または設定します。

Public Property MaxSize As Integer
[C#]
public int MaxSize {get; set;}
[C++]
public: __property int get_MaxSize();public: __property void set_MaxSize(int);
[JScript]
public function get MaxSize() : int;public function set MaxSize(int);

プロパティ値

ユーザーが選択できるポイント サイズの最大値。既定値は 0 です。

解説

ポイント サイズの最大値と最小値の設定を有効にするためには、 MaxSize の値が MinSize の値よりも大きく、さらに両方の値が 0 より大きい値である必要があります。

このプロパティの値を 0 より小さい値に設定しても、実際には 0 が使用されます。 MaxSizeMinSize より小さい値を設定すると、 MinSizeMaxSize に設定されます。 MinSize および MaxSize を同じ値に設定すると、選択できるフォント サイズが 1 つに限定されます。

ポイント サイズを 0 にした場合は、フォント サイズは制限されません。

使用例

[Visual Basic, C#] MinSize メンバ、 MaxSize メンバ、 ShowEffects メンバ、および FontMustExist メンバを使用して、Apply イベントを処理するコード例を次に示します。この例を実行するには、FontDialog1 という名前の FontDialog と Button1 という名前のボタンが配置されているフォームに、次のコードを貼り付けます。Button1 の Click イベントは、この例のイベント処理メソッドに必ず関連付けるようにしてください。

 
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

[C#] 
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    // Set FontMustExist to true, which causes message box error
    // if the user enters a font that does not exist. 
    FontDialog1.FontMustExist = true;
    
    // Associate the method handling the Apply event with the event.
    FontDialog1.Apply += new System.EventHandler(FontDialog1_Apply);

    // 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.
    System.Drawing.Font oldFont = this.Font;

    //Show the dialog, and get the result
    DialogResult result = 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)
    {
        FontDialog1_Apply(this.Button1, new System.EventArgs());
    }
        // If Cancel is clicked, set the font back to
        // the original font.
    else if (result == DialogResult.Cancel)
    {
        this.Font = oldFont;
        foreach ( Control containedControl in this.Controls)
        {
            containedControl.Font = oldFont;
        }
    }
}

// Handle the Apply event by setting all controls' fonts to 
// the chosen font. 
private void FontDialog1_Apply(object sender, System.EventArgs e)
{

    this.Font = FontDialog1.Font;
    foreach ( Control containedControl in this.Controls )
    {
        containedControl.Font = FontDialog1.Font;
    }
}

[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

FontDialog クラス | FontDialog メンバ | System.Windows.Forms 名前空間 | MinSize