Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

if Font exis

Posted on 2011-09-10
3
Medium Priority
?
300 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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