Results 1 to 12 of 12

Thread: How to Get Font Name and it's Own Styles.?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    How to Get Font Name and it's Own Styles.?

    Hello.........
    i have 2 Combo boxes[_cmbxFontName, _cmbxStyleName]
    i can load all installed fonts into _cmbxFontName. but i could not load Fonts Style. if i select a Font Name in _cmbxFontName then the other _cmbxstyleName combo box wants to load it's Styles [Regular,Normal,Bold,Italic......].
    i know all fonts has different styles but how can i found and load its....
    Thanks.............

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: How to Get Font Name and it's Own Styles.?

    can anybody help........?

  3. #3
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: How to Get Font Name and it's Own Styles.?

    Hi,

    You can try something like this:

    vb Code:
    1. Imports System.Drawing.Text
    2. Public Class Form1
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Dim installed_fonts As New InstalledFontCollection
    6.               For Each font_family As FontFamily In _
    7.             installed_fonts.Families
    8.                       ComboBox1.Items.Add(font_family.Name)
    9.         Next font_family
    10.      
    11.     End Sub
    12.  
    13.  Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    14.         ComboBox2.Font = New System.Drawing.Font(ComboBox1.SelectedItem.ToString, 25, FontStyle.Regular)
    15.     End Sub
    16. End Class
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to Get Font Name and it's Own Styles.?

    There's no property or method that will give you the list you want. What you have to do is, once you've got a Font, get its FontFamily first and then call IsStyleAvailable on that for each FontStyle value. Note that you're going to have to call it for composite values as well as discrete, e.g
    vb.net Code:
    1. Dim availableStyles As List(Of FontStyle)
    2.  
    3. If myFontFamily.IsStyleAvailable(FontStyle.Bold) Then
    4.     availableStyles.Add(FontStyle.Bold)
    5. End If
    6.  
    7. If myFontFamily.IsStyleAvailable(FontStyle.Italic) Then
    8.     availableStyles.Add(FontStyle.Italic)
    9. End If
    10.  
    11. If myFontFamily.IsStyleAvailable(FontStyle.Bold Or FontStyle.Italic) Then
    12.     availableStyles.Add(FontStyle.Bold Or FontStyle.Italic)
    13. End If
    You can make it nicer than that but you get the idea.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Smile Re: How to Get Font Name and it's Own Styles.?

    Quote Originally Posted by sparrow1 View Post
    Hi,

    You can try something like this:

    vb Code:
    1. Imports System.Drawing.Text
    2. Public Class Form1
    3.  
    4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.         Dim installed_fonts As New InstalledFontCollection
    6.               For Each font_family As FontFamily In _
    7.             installed_fonts.Families
    8.                       ComboBox1.Items.Add(font_family.Name)
    9.         Next font_family
    10.      
    11.     End Sub
    12.  
    13.  Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    14.         ComboBox2.Font = New System.Drawing.Font(ComboBox1.SelectedItem.ToString, 25, FontStyle.Regular)
    15.     End Sub
    16. End Class

    Thanks For your Help Sparrow.......

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: How to Get Font Name and it's Own Styles.?

    Quote Originally Posted by jmcilhinney View Post
    There's no property or method that will give you the list you want. What you have to do is, once you've got a Font, get its FontFamily first and then call IsStyleAvailable on that for each FontStyle value. Note that you're going to have to call it for composite values as well as discrete, e.g
    vb.net Code:
    1. Dim availableStyles As List(Of FontStyle)
    2.  
    3. If myFontFamily.IsStyleAvailable(FontStyle.Bold) Then
    4.     availableStyles.Add(FontStyle.Bold)
    5. End If
    6.  
    7. If myFontFamily.IsStyleAvailable(FontStyle.Italic) Then
    8.     availableStyles.Add(FontStyle.Italic)
    9. End If
    10.  
    11. If myFontFamily.IsStyleAvailable(FontStyle.Bold Or FontStyle.Italic) Then
    12.     availableStyles.Add(FontStyle.Bold Or FontStyle.Italic)
    13. End If
    You can make it nicer than that but you get the idea.
    Yes..!..Yes..! this is i am expecting one .......
    but different fonts has different Styles Name ...
    how can i find that Mr.jmcilhinney

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to Get Font Name and it's Own Styles.?

    I think sparrow1 has misinterpreted the question, or else I have. sparrow1's code will display the name of a font in that font, which I don't think is what you're getting at. You want a list of styles that can be selected for the selected font, right?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to Get Font Name and it's Own Styles.?

    Quote Originally Posted by medsont View Post
    Yes..!..Yes..! this is i am expecting one .......
    but different fonts has different Styles Name ...
    how can i find that Mr.jmcilhinney
    I just told you how.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: How to Get Font Name and it's Own Styles.?

    In Photoshop has that option


    Uploaded with ImageShack.us

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Location
    TamilNadu, India
    Posts
    249

    Re: How to Get Font Name and it's Own Styles.?

    Quote Originally Posted by jmcilhinney View Post
    I think sparrow1 has misinterpreted the question, or else I have. sparrow1's code will display the name of a font in that font, which I don't think is what you're getting at. You want a list of styles that can be selected for the selected font, right?
    Yes i know that but i say Thanks for him bcz he spend his time for my questions thats all.

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to Get Font Name and it's Own Styles.?

    Quote Originally Posted by medsont View Post
    Yes i know that but i say Thanks for him bcz he spend his time for my questions thats all.
    I wasn't suggesting that you shouldn't thank someone who made an effort on your behalf. I was just trying to make a clear statement of the problem so I, and others, could be sure of exactly what it was.

    We don't need an image. We have a clear statement of the problem and I've provided a solution. What exactly is your issue now? Have you done what I suggested? If not, why not? If so, did it work? If not, what exactly did you do and what exactly happened?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to Get Font Name and it's Own Styles.?

    Actually, looking at that image, that is not the same information that you get using the Font and related classes in Windows Forms. If you use the FontFamily.Families property, you get Arial, Arial Black and Arial Narrow as three different families and the number of styles is limited to the five provided by the FontStyle enumeration. If you want to see the information in that image, I think that you'd probably have to do so using the Windows API. I couldn't tell you how.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width