Fill ComboBox with List of available Fonts

后端 未结 7 2265
無奈伤痛
無奈伤痛 2020-12-10 00:29

How can I fill a combo-box with a list of all the available fonts in the system?

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 00:53

    This is the easy way to do it. It includes two comboboxes 1 for the font name and one for the font size

     public FontFamily[] Families { get; }
    
    
     private void Form1_Load(object sender, EventArgs e)
        {
    
            foreach (FontFamily oneFontFamily in FontFamily.Families)
            {
                comboBox1.Items.Add(oneFontFamily.Name);
            }
    
            comboBox1.Text = this.richTextBox1.Font.Name.ToString();
            comboBox2.Text = this.richTextBox1.Font.Size.ToString();
    
            richTextBox1.Focus();
    
        }
    
    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
    
             float size = Convert.ToSingle(((ComboBox)sender).Text);
    
            richTextBox1.SelectionFont = new Font(richTextBox1.Font.FontFamily, size);
        }
    

提交回复
热议问题