PowerTools PlusPak for Windows Forms 8.0J
AllFonts プロパティ
使用例 

すべてのフォントグループにフォント名項目として表示される、FontInfoオブジェクトの読み取り専用コレクションを取得します。
構文
Public ReadOnly Property AllFonts As FontInfoReadOnlyCollection
public FontInfoReadOnlyCollection AllFonts {get;}

プロパティ値

ユーザーがこのGcFontPickerコントロールのドロップダウンリストから選択できるすべてのFontInfoオブジェクトを含むFontInfoReadOnlyCollection
解説

AllFontsは読み取り専用コレクションであり、ユーザーはこのコレクションを変更する可能性のある操作をこのコレクションに対して実行することはできません。AllFontsコレクションに含まれるFontInfoオブジェクトは、GcFontPickerコントロールのドロップダウンリストのすべてのフォントグループにフォント名項目として表示されます。

デフォルトでは、AllFontsコレクションには、システムに現在インストールされているすべてのフォントを表すすべてのFontInfoオブジェクトが含まれます。AllFonts内のFontInfoオブジェクトは、ItemFilterプロパティを使用してフィルタリングできます。このコレクションをフィルタリングするために実行できるタスクの詳細については、FontInfoFilterクラスのリファレンストピックを参照してください。

使用例

次のサンプルコードは、AllFontsプロパティの使用方法を示します。この例では、listBoxという名前のSystem.Windows.Forms.ListBoxコントロールに、AllFontsに含まれるすべてのFontInfo項目を格納し、GcFontPickerSystem.Windows.Forms.ListBoxコントロールを組み合わせてSystem.Windows.Forms.FontDialogのフォント名セレクターのような動作を実現しています。そのため、この例をもとにして、GcFontPickerコントロールを利用したフォント名セレクターSystem.Windows.Forms.UserControlを迅速に開発できます。このサンプルコードを実行するには、System.Windows.Forms.Formプロジェクトを作成し、gcFontPickerという名前のGcFontPickerと、listBoxという名前のSystem.Windows.Forms.ListBoxを追加して、以下のコードをプロジェクトに貼り付けます。そして、ここで作成したメソッドをコンストラクターまたはフォーム上の別のメソッドから呼び出します。

private void CreateGcFontPickerWithAllFonts()
{
    // Initialize the Name and Location of the gcFontPicker.
    gcFontPicker.Location = new Point(10, 5);
    // Remove the DropDownButton.
    gcFontPicker.SideButtons.Clear();
    // Acitve the auto complete string.
    gcFontPicker.AutoCompleteMode = AutoCompleteMode.Append;
    // Highlight the text when gcFontPicker gets foucs.
    gcFontPicker.HighlightText = true;

    // Initialize listBox.
    listBox.Location = new Point(10, 25);
    listBox.Size = new Size(120, 90);

    // Copy all of the FontInfo items into an array.
    FontInfo[] fonts = new FontInfo[gcFontPicker.AllFonts.Count];
    gcFontPicker.AllFonts.CopyTo(fonts, 0);

    // Fill the listBox with all the fontInfo items in gcFontPicker.
    listBox.Items.AddRange(fonts);

    // Update the selected index of listBox when gcFontPicker TextChanged.
    gcFontPicker.TextChanged += new EventHandler(gcFontPicker_TextChanged);

    // Update the selected font of gcFontPicker when listBox SelectedIndexChanged.
    listBox.SelectedIndexChanged += new EventHandler(listBox_SelectedIndexChanged);
}

private void gcFontPicker_TextChanged(object sender, EventArgs e)
{
    listBox.SelectedItem = gcFontPicker.AllFonts[gcFontPicker.Text];
}

private void listBox_SelectedIndexChanged(object sender, EventArgs e)
{
    gcFontPicker.SelectedFontInfo = listBox.SelectedItem as FontInfo;
}
Private Sub CreateGcFontPickerWithAllFonts()
    ' Initialize the Name and Location of the gcFontPicker.
    gcFontPicker.Location = New Point(10, 5)
    ' Remove the DropDownButton.
    gcFontPicker.SideButtons.Clear()
    ' Acitve the auto complete string.
    gcFontPicker.AutoCompleteMode = AutoCompleteMode.Append
    ' Highlight the text when gcFontPicker gets foucs.
    gcFontPicker.HighlightText = True

    ' Initialize listBox.
    listBox.Location = New Point(10, 25)
    listBox.Size = New Size(120, 90)

    ' Copy all of the FontInfo items into an array.
    Dim fonts As FontInfo() = New FontInfo(gcFontPicker.AllFonts.Count - 1) {}
    gcFontPicker.AllFonts.CopyTo(fonts, 0)

    ' Fill the listBox with all the fontInfo items in gcFontPicker.
    listBox.Items.AddRange(fonts)

    ' Update the selected index of listBox when gcFontPicker TextChanged.
    AddHandler gcFontPicker.TextChanged, AddressOf gcFontPicker_TextChanged

    ' Update the selected font of gcFontPicker when listBox SelectedIndexChanged.
    AddHandler listBox.SelectedIndexChanged, AddressOf listBox_SelectedIndexChanged
End Sub

Private Sub gcFontPicker_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
    listBox.SelectedItem = gcFontPicker.AllFonts(gcFontPicker.Text)
End Sub

Private Sub listBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    gcFontPicker.SelectedFontInfo = TryCast(listBox.SelectedItem, FontInfo)
End Sub
プラットフォーム

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

参照

GcFontPicker クラス
GcFontPicker メンバ
FontInfoFilter クラス
FontInfoFilter クラス

Send Feedback