Page 1 of 1

Fonts in Combo box help!!

Posted: Sat Nov 13, 2010 4:32 pm
by superboy_7777
Hi guys,
I just wanted to know how I could display fonts in a combo box.
The thing is I am working on a MS Word like application!!
Thanks in advance!!
superboy_7777

Re: Fonts in Combo box help!!

Posted: Sat Nov 13, 2010 4:48 pm
by Bogoh67
try this
Code: Select all
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each FontType In System.Drawing.FontFamily.Families
            ComboBox1.Items.Add(FontType.Name)
        Next
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        RichTextBox1.Font = New Font(ComboBox1.SelectedItem.ToString, 10, FontStyle.Regular)
    End Sub

Re: Fonts in Combo box help!!

Posted: Sat Nov 13, 2010 4:48 pm
by Agust1337
You can also try this

Form_Load:
Code: Select all
        Dim Fonts As New System.Drawing.Text.InstalledFontCollection()
        Dim Family As FontFamily
        For Each Family In Fonts.Families
            ComboBox1.Items.Add(Family.Name)
        Next

Re: Fonts in Combo box help!!

Posted: Sat Nov 13, 2010 5:35 pm
by superboy_7777
Thanks Bogoh67 and Agust1337.
Just one more thing.
How do I get font sizes in combo boxes and apply them in a Rich Text Box.
Thanks in advance!!
superboy_7777

Re: Fonts in Combo box help!!

Posted: Sat Nov 13, 2010 5:56 pm
by Agust1337
Hello Superboy_7777,
Heres how to change the font but on the Selected Text:

On the combobox with the size(i named it cbSize, and cbFonts has the fonts)

cbSize_SelectedIndexChanged()
Code: Select all
 Try
            Dim nFont As New Font(cbFonts.Text, cbSize.Text)
            RichTextBox1.SelectionFont = nFont
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
*Edit: I use Try so the program will not crash.