• 0

[VB.NET] Help with Font ComboBox


Question

Ok...I'm working on a simple type word processor. Just soemthing to play with cuz I got bored. Anyways...I'm trying to set a combobox near the top of the form that has all the installed fonts and you can choose your font from there. Simple enough I would assume. I have as much as the combobox listing the installed fonts.

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

Now...what I can't get is the selection process down. 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!

Link to comment
https://www.neowin.net/forum/topic/292320-vbnet-help-with-font-combobox/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

I'm not sure if I understand what you want, but if you want to know how to use the SelectedIndexChanged event, just double click the combo box in the form designer, assuming you use VS.NET or SharpDevelop, and it will create the code for you. All you need to do is to enter the right code to the function.

  • 0

I understand HOW to enter code. I've been working with VS.NET for a few years on and off.

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?

Hope that explains a little better on what I'm trying to do. Thanks!

  • 0

Oh, sorry - I didn't understand you :blush: Ok do this:

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

Assuming that you have a combo box called comboBox1 and a text box called textBox1. It should take the selcted index of the com box and use it to find the index number of the font inside ComboFonts.Families.

Good luck :D

  • 0

Thank you very much! It worked! Do you happen to know how to make the name listed in the combobox look like the font itself? Just something I thought of. I may be able to figure it out myself with a little playing.

Thanks again!

  • 0
  fourinjuly4ij said:
Thank you very much!  It worked!  Do you happen to know how to make the name listed in the combobox look like the font itself?  Just something I thought of.  I may be able to figure it out myself with a little playing.

Thanks again!

585564430[/snapback]

i'm pretty sure you're going to have to owner draw the combo box to do that...

here's a link that might help, but i didn't look too closely at it:

http://www.csharphelp.com/archives/archive262.html (its for C# but the principle would be the same)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.