Solved

if Font exis

Posted on 2011-09-10
3
289 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

13 Experts available now in Live!

Get 1:1 Help Now