Help with Font ComboBox

fourinjuly4ij

New member
Joined
Mar 3, 2005
Messages
3
Programming Experience
3-5
Ok...I'm working on a simple type word processor. Just soemthing to play with cuz I got bored. I have a combobox thats filled with all the font familes on my system. I want to be able to select a font from the combobox and have that selection be the font for my TextBox that is the word processor.

So I have a Menu, a Toolbar, a Textbox (to type in), and now a Comboxbox (up near the toolbar which lists all the fonts installed on my system). How do I select one of those fonts in the Combobox and have it become the font for my Textbox?

Here's what I have in the Form Load Event.

VB.NET:
Private Sub frmScribble_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'set font combobox
 	   Dim ComboFonts As Drawing.Text.InstalledFontCollection
 	   ComboFonts = New Drawing.text.InstalledFontCollection
 	   Dim Family As FontFamily
 	   For Each Family In ComboFonts.Families
 		   cboFonts.Items.Add(Family.Name)
 	   Next

 	   cboFonts.SelectedIndex = 0

End Sub

I figure I need to use the SelectedIndexChange event from the combobox control, but from there I'm stuck. Can anyone help me with this problem?

Thanks!
 
This is what I found out...

VB.NET:
Sub ComboBox1SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
  	Me.textBox1.Font = New System.Drawing.Font(ComboFonts.Families(comboBox1.SelectedIndex), 13, Font.Style)
  End Sub

And it worked!
 

Latest posts

Back
Top