• 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

    • Hopefully this will turn out to be the same/better than the old LOTR BFME series. Been nothing decent on the RTS scene for a long time now. Anything that does come out tends to be pretty mediocre. A new C&C Generals series would sell well
    • It make sense only if they want to hide the minority of changes of each new version
    • Trade up with Sterling Stock Picker now price dropped by 85% by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can save 85% off on a lifetime subscription to Sterling Stock Picker. Sterling Stock Picker (SSP) is an award-winning platform designed to make stock investing accessible to everyone, regardless of expertise. The software offers multiple methods to identify winning stocks that align with your personal values, investment preferences, and risk tolerance. By handling all the complex calculations, it allows you to focus on making informed investment decisions. The patent-pending North Star technology provides clear guidance on whether to buy, sell, hold, or avoid a particular stock. Ask Finley, your personal AI financial coach Finley is your personal AI financial coach providing real-time data access, strategic investment advice, risk assessment, and educational support to help you make informed decisions. Whether you're a seasoned investor or just starting, Finley is equipped to help you achieve your financial goals. Feel free to ask any questions about your portfolio or the stock market. PERSONALIZED FINANCIAL GUIDANCE Custom Recommendations: Get stock picks tailored to your risk tolerance, portfolio performance, and investment goals. Dynamic Insights: Access detailed financial, technical, earnings, growth, and risk analysis for smarter investing. ENHANCED PORTFOLIO MANAGEMENT Done-For-You Portfolio Builder: Easily construct a diversified portfolio based on your risk tolerance and investment goals. Analysis and Suggestions: Receive data-driven portfolio adjustments to optimize returns based on your risk acceptance score. Risk Assessment Overview: Understand your risk level and receive stock recommendations aligned with your investment strategy. STRATEGIC INVESTMENT ADVICE Stock Rockets: Discover top-performing companies with over 50% quarterly revenue growth and the highest North Star rankings. Concentrated Portfolio Strategy: Focus on high-potential stocks instead of broad diversification to maximize growth. Industry and Sector Insights: Stay ahead with detailed performance narratives and sector-specific trends. EDUCATIONAL SUPPORT & COMMUNITY Verbose Explanations: Break down complex financial concepts with in-depth explanations for beginners. Investment Strategies: Learn and apply various investment strategies with expert-backed insights. Community Chat Forum: Connect with fellow investors to share insights, ask questions, and discuss investment strategies. Build your Stock Portfolio in 3 easy steps! Discover Your Risk Tolerance: Take a quick 5-minute questionnaire to assess your ability to handle risk effortlessly. Search Stocks Aligned With Your Personal Values: Use an intuitive stock-picking interface to confidently find winning stocks. Build Your Portfolio: Utilize the Done-For-You Portfolio Builder to simplify investing and remove the guesswork. Good to know: Length of access: lifetime Redemption deadline: redeem your code within 30 days of purchase Access options: desktop or mobile Only available to new users Updates included A lifetime subscription to Sterling Stock Picker normally has a suggested price of $486, but you can pick it up for just $68.99 for a limited time - that represents a saving of $417 (85% off). For a full description, specs, and license info, click the link below. Sterling Stock Picker lifetime subscription for $68.99 (was $486) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • What if... both hardware AND software (due to their annual release cycles) got matching year release numbers? iPhone Pro 26 releases with iOS 26... For Macs, that'd be MacBook Pro 2026 releases with macOS 26 baked-in. With this proposal, the Major Version signifies latest-stable for both hardware and software, and gives them wiggle-room to optimize iOS releases for older hardware by a few months... while also incentivizing consumers to upgrade hardware for the latest-greatest software. (It would double-down on breaking their old support strategy but that's not a bad thing.)
    • Why doesn't Microsoft post updated the ISOs on the website, then have users download new install media? Too simple and obvious? Sometimes I swear Microsoft is a Government operation!!
  • Recent Achievements

    • Week One Done
      abortretryfail earned a badge
      Week One Done
    • First Post
      Mr bot earned a badge
      First Post
    • First Post
      Bkl211 earned a badge
      First Post
    • One Year In
      Mido gaber earned a badge
      One Year In
    • One Year In
      Vladimir Migunov earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      492
    2. 2
      +FloatingFatMan
      256
    3. 3
      snowy owl
      248
    4. 4
      ATLien_0
      226
    5. 5
      +Edouard
      190
  • Tell a friend

    Love Neowin? Tell a friend!