Input for WinForms | ComponentOne
Input Controls / FontPicker
In This Topic
    In This Topic

    FontPicker is a font selection control that lets users pick the desired font from a drop-down list. Users can select out of a list of more than 250 fonts available in the FontPicker. The FontPicker also supports additional visual styles and themes to choose from so that the users can further customize their desktop applications.

     When you click the dropdown button of the FontPicker control, it's interface looks similar to the following image:

    You can browse through the list to see the available fonts.


    FontPicker comprises of three parts: textbox or editor, dropdown button and dropdown list.

    Add FontPicker

    You can add the FontPicker control using the C1FontPicker class as depicted in the code snippet below:

    Copy Code
    // Initialize the FontPicker control and add the control to the Form
     this.c1FontPicker1 = new C1.Win.Input.Pickers.C1FontPicker();
     this.c1FontPicker1.Location = new System.Drawing.Point(105, 81);
     this.c1FontPicker1.Name = "c1FontPicker1";
     this.c1FontPicker1.Size = new System.Drawing.Size(200, 50);

    You can use FontPicker with controls like RichTextBox, such that the font of the selected text in RichTextBox gets altered as you pick any font in the FontPicker. For this purpose, the C1FontPicker class provides the SelectedFontFamilyChanged event, which fires when the SelectedFontFamily property changes.

    Observe the code snippet below to set this event:

    Copy Code
          // Fires when the SelectedFontFamily property changes
          private void c1FontPicker1_SelectedFontFamilyChanged(object sender, EventArgs e)
              if (richTextBox1.SelectionFont != null)
                  richTextBox1.SelectionFont = new Font(((C1.Win.Input.Pickers.C1FontPicker)sender).SelectedFontFamily, richTextBox1.SelectionFont.Size, richTextBox1.SelectionFont.Style);

    Customize FontPicker

    You can customize the FontPicker and change the dropdown alignment, dropdown width and the text alignment in FontPicker editor using the DropDownAlign, DropDownWidth and TextAlign properties.

    The code snippet below shows how to set these properties:

    Copy Code
    this.c1FontPicker1.Location = new System.Drawing.Point(17, 220);
    this.c1FontPicker1.Name = "c1FontPicker1";
    this.c1FontPicker1.Size = new System.Drawing.Size(200, 25);
    this.c1FontPicker1.DropDownAlign = C1.Win.Input.DropDownAlignment.Center;
    this.c1FontPicker1.DropDownWidth = 300;
    this.c1FontPicker1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;

    Change Item Size

    FontPicker lets you alter the size of the items in the dropdown form of the control. For this purpose, the C1FontPicker class provides the ItemFontSize property.

    The snapshot below depicts a FontPicker control with the ItemFontSize set as 15.

    The code snippet below shows how to set this property:

    Copy Code
    c1FontPicker1.ItemFontSize = 15;