• 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

    • Building 100 hospitals around the world would have spent his fortune easily. But that would not keep him at the table with the elites in the world for the rest of his life. Or keep him from chanting about how good he is to the poor people around the globe to the media.
    • Exactly. that's what I use when I do use Windows 10 on my Linux through QEMU/KVM VM (the 'activation' is tied to the UUID of the VM) and, like you said, that Jan 2032 version of Win10, even if decent program/game support ends earlier than Jan 2032, I suspect, for a conservative figure, that we got at least 2-3 years from now (so call it 2027-2028) before Win10 may start to become more of a legitimate issue. but for general usage I suspect we got a 'easy' 2-3+ years. because like you say, as long as browsers don't start to become a issue, all the more reason to continue using Win10 for many, probably most, people. even when it comes to browsers, you mentioned Firefox supports Win7 until end of August etc... but I think it's just ESR releases which, while I get it technically works, are when browser support is getting a bit long-in-the-tooth. but as long as the standard Firefox release is still supported, then one is still easily well within the 'good support range', which my comment basically plays inline with what Werct said, which I suspect comes back to my 2027-2028 estimate before Win10 'starts' to legitimately fade off into the sunset
    • Intel's new GPU driver adds support for FBC: Firebreak, Stellar Blade, and more by Taras Buria Intel has released a new non-WHQL driver under version 32.0.101.6876. The update brings support and optimizations for four games and a single fix for visual artifacts that appear in certain situations. Here is the list of newly-supported games in driver 32.0.101.6876 on systems with Intel Arc B-Series, A-Series, and Intel Core Ultra with built-in Arc graphics: FBC: Firebreak Rematch Stellar Blade Tom Clancy's Rainbow Six Siege X There is also a single bug fixed in today's release: Intermittent visual artifacts may appear in certain usage scenarios. Known issues remain the same as in the latest WHQL release, except for a new bug that causes audio glitches on handheld devices: Certain handheld devices may experience audio glitches and lower-than-expected performance while audio is playing. You can mitigate the problem by following a guide that Intel published on the official forum. It requires reinstalling the graphics and NPU drivers on the affected systems. A proper fix will be available in a future driver update. You can install Intel 32.0.101.6876 non-WHQL driver on PCs with 64-bit Windows 10 and Windows 11 with the following graphics products from Intel: Discrete GPUs Integrated GPUs Intel Arc A-Series (Alchemist) Intel Arc B-Series (Battlemage) Intel Iris Xe Discrete Graphics (DG1) Intel Core Ultra Series 2 (Lunar Lake and Arrow Lake) Intel Core Ultra (Meteor Lake) Intel Core 14th Gen (Raptor Lake Refresh) Intel Core 13th Gen (Raptor Lake) Intel Core 12th Gen (Alder Lake) Intel Core 11th Gen (Tiger Lake) You can download the driver from the official website here. Full release notes are available here (PDF). Keep in mind that this is a non-WHQL driver, which means it could be less stable than certified WHQL drivers.
    • He did give it away in 2008, well actually he gave away half of his fortune. He was open at the time that part of the reason he was doing it was that he was accumulating wealth faster than he could conceive of spending it
    • ooof! made me wince when i saw where the stand connected!
  • Recent Achievements

    • Dedicated
      jbatch earned a badge
      Dedicated
    • Week One Done
      Leonard grant earned a badge
      Week One Done
    • One Month Later
      portacnb1 earned a badge
      One Month Later
    • Week One Done
      portacnb1 earned a badge
      Week One Done
    • First Post
      m10d earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      266
    2. 2
      snowy owl
      158
    3. 3
      +FloatingFatMan
      145
    4. 4
      ATLien_0
      140
    5. 5
      Xenon
      131
  • Tell a friend

    Love Neowin? Tell a friend!