Solved

if Font exis

Posted on 2011-09-10
3
290 Views
Last Modified: 2012-06-27
Hi,
I'm working with application that :
give to the user change font name
change the font style and font size.
To show all available fonts I use:
 Dim InstalledFonts As New InstalledFontCollection
        ' Gets the array of FontFamily objects associated with this FontCollection.
        Dim fontfamilies() As FontFamily = InstalledFonts.Families()
        '   Populates font combobox with the font name
        For Each fontFamily As FontFamily In fontfamilies
               If Font.SystemFontName = True Then
                   cboFont.Items.Add(fontFamily.Name)
                End If
        Next
Now sometimes user change the font. style that can't be used with selected font name and in this case the application hangs.
 TextFont = New System.Drawing.Font(FontName, FontSize, FontStyle)
How can I check out if this font can be used or not.

I hope you can help me.
0
Comment
Question by:mastiSoft
3 Comments
 
LVL 40
ID: 36517142
If Font.SystemFontName = True AndAlso Me.Font.FontFamily.IsStyleAvailable(Font.Style) Then
    cboFont.Items.Add(fontFamily.Name)
Else
    MessageBox.Show("Font not compatible with request.")
End If
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 36517144
I don't think there is an ~elegant~ way to do this.  You can use a Try/Catch block and disable that combination if it doesn't work.

One possibility is to create a Font using the Constructor that accepts either the Font name as a String or just the FontFamily without any styles.  Then use the IsStyleAvailable() method to determine if that Font supports the Style you want:
http://msdn.microsoft.com/en-us/library/system.drawing.fontfamily.isstyleavailable.aspx

If it does, then create the Font again with the desired style...
0
 
LVL 1

Author Closing Comment

by:mastiSoft
ID: 36518329
Yes that are exactly what I needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now