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.
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
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
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
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
You can also try this
Form_Load:
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
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
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
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()
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
*Edit: I use Try so the program will not crash. Try
Dim nFont As New Font(cbFonts.Text, cbSize.Text)
RichTextBox1.SelectionFont = nFont
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023