Solved

if Font exis

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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