Solved

if Font exis

Posted on 2011-09-10
3
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 86

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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