• 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.
  • Posts

    • I was a little disappointed with mine compared to the Lemokey P1, for example. Seemed cheap compared to all aluminum. But I liked the look to go with my Fractal North. Ended up getting a Keychron Q1 HE and a Lemokey L5 HE. Love the L5, which replaced my P1. The definitely aren't light boards.
    • Thunderbird 139.0.2 by Razvan Serea Thunderbird is a free, open-source, cross-platform application for managing email and news feeds. It is a local (rather than a web-based) email application that is powerful yet easy-to-use. Thunderbird is clean and elegant by default, but easily customizable to match your workflow and visual preferences. It is loaded with unique and powerful features. Thunderbird is developed, tested, translated and supported by the folks at Mozilla Corporation and by a group of dedicated volunteers. Thunderbird gives you control and ownership over your email. There are lots of add-ons available for Thunderbird that enable you to extend and customize your email experience. Thunderbird gives you IMAP/POP support, a built-in RSS reader, support for HTML mail, powerful quick search, saved search folders, advanced message filtering, message grouping, labels, return receipts, smart address book LDAP address completion, import tools, and the ability to manage multiple e-mail and newsgroup accounts. Thunderbird 139.0.2 fixes: Security fixes Download: Thunderbird 139.0.2 for Windows (EN/US) | 32-bit | ~70.0 MB (Open Source) Download: Thunderbird 139.0.2 for Linux (EN/US) | 74.7 MB Download: Thunderbird 139.0.2 for Mac OS (EN/US) | 127.0 MB Download: Thunderbird 139.0.2 in other languages View: Thunderbird Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Thanks Nik and thanks Mind. Nik: Just on the off chance, you don't know where I could get this part at cheaper than normal price do you? I tried I few places but the I can find it at is 70GBP? Just gonna have to suck it up and buy the add-on for my PC. Thank you guys.
    • Underwhelming update. Same as 12,13,14,15. Then M3E ain't showing up until Q3
  • Recent Achievements

    • Week One Done
      elsa777 earned a badge
      Week One Done
    • One Month Later
      elsa777 earned a badge
      One Month Later
    • First Post
      K Dorman earned a badge
      First Post
    • Reacting Well
      rshit earned a badge
      Reacting Well
    • Reacting Well
      Alan- earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      544
    2. 2
      ATLien_0
      272
    3. 3
      +FloatingFatMan
      207
    4. 4
      +Edouard
      201
    5. 5
      snowy owl
      139
  • Tell a friend

    Love Neowin? Tell a friend!