Fonts in Combo box help!!

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
superboy_7777
New Member
New Member
Posts: 10
Joined: Tue Sep 21, 2010 10:39 am

Fonts in Combo box help!!
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
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Fonts in Combo box help!!
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
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Fonts in Combo box help!!
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
Top-notch casual Dating
User avatar
superboy_7777
New Member
New Member
Posts: 10
Joined: Tue Sep 21, 2010 10:39 am

Re: Fonts in Combo box help!!
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
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Fonts in Combo box help!!
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.
Top-notch casual Dating
5 posts Page 1 of 1
Return to “Coding Help & Support”