• 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

    • Been using Linux for the last 15-16 years, and I don't agree to any of this.. Come on, guys..
    • Crucial 8TB X10 2100 MB/s USB-C (3.2) external SSD is priced lowest ever at just $440 by Sayan Sen External SSDs are great as their portability makes them quite convenient. If you are shopping for one, then Micron has a deal that may just be right for you. The company's Crucial X10 external SSDs are currently on sale for their lowest ever prices (purchase links down below). What is interesting about the Pro X9 and X10 models is that they are based on TLC or triple-level cell NAND compared to QLC or quad-level on the X6 and X8 external SSDs, making them higher endurance and better for longer sustained reads and writes. Unfortunately, Crucial does not specifically state the kind of NAND flash the X10 has, though, from its three-year warranty, as opposed to five years on the Pro models, it can be said that the drive is QLC. As such it is not the ideal drive for constant data reads and writes, but you can certainly use it fairly often. Speaking of reads and writes, Crucial promises up to 2100 MB/s sequential reads. To enable such speeds, the SSD supports USB 3.2 Gen-2 2x2 interface and comes with a Type-C to Type-C USB cable in the box. But it is also backward compatible with USB 3.2 Gen 2/USB 3.2 Gen1/USB 3.1 Gen1/ USB 3.0 (5Gb/s), so this would mean lower speeds. In terms of durability, the X10 Pro and X9 Pro pack IP65 water and dust resistance, and the firm claims that the drive's drop-proof durability is up to 9.8 feet or about 3 meters. Get the Crucial X10 at the link below: Crucial X10 8TB Portable SSD, Up to 2,100MB/s, USB 3.2 USB-C, Compatible with Windows, Mac & Android, Blue - CT8000X10SSD9-02: $439.99 (Amazon US first-party seller) This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
  • Recent Achievements

    • Conversation Starter
      johnwin1 earned a badge
      Conversation Starter
    • One Month Later
      Marwin earned a badge
      One Month Later
    • One Year In
      fred8615 earned a badge
      One Year In
    • Week One Done
      Jim Dugan earned a badge
      Week One Done
    • Week One Done
      Adam Todd earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      215
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      134
    4. 4
      Xenon
      127
    5. 5
      +FloatingFatMan
      117
  • Tell a friend

    Love Neowin? Tell a friend!