Click here to Skip to main content
15,878,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have two comboboxes combobox1 & combobox2 i am getting all system fonts in combobox1 i need to get fontstyles of a select font in combobox2

VB
Dim fc As New Drawing.Text.InstalledFontCollection
   Dim ff As FontFamily() = fc.Families()
   For Each family As FontFamily In ff
       Me.ComboBox1.Items.Add(family.Name)
   Next

when i select font name for eg. Monotype Corsiva font have only italic & italic bold font style

in brief i need to get fontstyles related to the font i select in combobox1 because fontstyles are different for different fonts
Posted

 
Share this answer
 
Comments
Omkaara 20-Nov-12 7:31am    
i have tried that it add each & every fontstyles to combobox what i need is i should get fontstyles related to selected font like i said in question Monotype Corsiva font have only italic & italic bold font style so only two of these styles will be added to 2nd combobox when i select font in 1st combobox
I think the way to do this to test each of the styles Regular, Bold, Italic and Bold|Italic with the FontFamily.IsStyleAvailable[^] method.

I have also seen (Book, Programming Microsoft Windows Forms, Charles Petzold, Microsoft Press, 2006) trial creation of a font in each style with exception trapping, but can't think of any reason to prefer this over the explicit style availability test.

Alan.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900