c# - how to bind a combobox with fonts names

c# - how to bind a combobox with fonts name

                                                                                                                           

In This C# Tutorial We Will See How We Can Populate A ComboBox With Fonts Name And Set The Font Name To A Label Using CSharp Programming Language


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class ComboBox_Fonts_Names : Form
    {
        public ComboBox_Fonts_Names()
        {
            InitializeComponent();
        }

        private void ComboBox_Fonts_Names_Load(object sender, EventArgs e)
        {
            foreach(FontFamily font in FontFamily.Families)
            {
                comboBox1.Items.Add(font.Name.ToString());
            }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                label1.Font = new Font(comboBox1.Text, label1.Font.Size);
            }
            catch { }
        }
    }
}

=> OutPut :


C# ComboBox With Fonts Names
Populate A ComboBox With Fonts Names In C#



Share this

Related Posts

Previous
Next Post »