Combobox populated by Fonts

exiletgm

Member
Joined
May 14, 2007
Messages
14
Programming Experience
1-3
I have an application that I am trying to populate a combobox with fonts from the system. I have been able to find code that does this from MSDN website.
VB.NET:
Dim ff As FontFamily
        For Each ff In System.Drawing.FontFamily.Families
            ComboBox2.Items.Add(ff.Name)
        Next

My issue now is to display one of these given fonts as the default. Say for instance I want to set the default font that is displayed to Arial or Segoe UI.

Thanks in advance.
 
You could append the string "(default)" to the default item. You could also set DrawMode=OwnerDrawFixed and handle the DrawItem event to draw the default item in some recognizable manner, for example bolding or colorizing it.
 
How would I go about adding the default string to one of the fonts? I never specify that the font arial exists, though it is in the combobox on runtime.
 
This is how you append the string:
ComboBox2.Items.Add(ff.Name & " (default)")
 
That works but it doesn't do what I was trying to do. I ended up playing with the code until I found this. It selects the Font even though it is in the middle of the Combobox's array.

VB.NET:
ComboBox2.SelectedItem = ("Arial")

Thank you again for your help.
 
Yes, do enjoy the simple things in life :) Doing that works for selection, and user can see when dropping the combo what item is currently selected, but if you have a default choice for the list and user selects a different item then user will no longer know what item was default. Maybe you have a different interpretation of what "default" is than me.
 
I was thinking similar to the way Micro$fot Word handles the font combobox. A style is set as default so the box isn't empty when to program first loads but is still able to be set by the user without a glaring notification that they are no longer using the default font style. :D
 
You can make the initial selection, and it doesn't have to reflect a default state/value. In many dialogs you will see for instance that they add an extra item with the text "Default" that you can choose instead of a specific item value, the Visual Studio fonts & colors dialog (options) is an example of this way of letting user choose freely while still able to find and set one particular default.
 
Back
Top