How to Get Font Name and it's Own Styles.?
Hello.........:wave:
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.............
Re: How to Get Font Name and it's Own Styles.?
can anybody help........?:wave:
Re: How to Get Font Name and it's Own Styles.?
Hi,
You can try something like this:
vb Code:
Imports System.Drawing.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim installed_fonts As New InstalledFontCollection
For Each font_family As FontFamily In _
installed_fonts.Families
ComboBox1.Items.Add(font_family.Name)
Next font_family
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Font = New System.Drawing.Font(ComboBox1.SelectedItem.ToString, 25, FontStyle.Regular)
End Sub
End Class
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:
Dim availableStyles As List(Of FontStyle)
If myFontFamily.IsStyleAvailable(FontStyle.Bold) Then
availableStyles.Add(FontStyle.Bold)
End If
If myFontFamily.IsStyleAvailable(FontStyle.Italic) Then
availableStyles.Add(FontStyle.Italic)
End If
If myFontFamily.IsStyleAvailable(FontStyle.Bold Or FontStyle.Italic) Then
availableStyles.Add(FontStyle.Bold Or FontStyle.Italic)
End If
You can make it nicer than that but you get the idea.
Re: How to Get Font Name and it's Own Styles.?
Quote:
Originally Posted by
sparrow1
Hi,
You can try something like this:
vb Code:
Imports System.Drawing.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim installed_fonts As New InstalledFontCollection
For Each font_family As FontFamily In _
installed_fonts.Families
ComboBox1.Items.Add(font_family.Name)
Next font_family
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
ComboBox2.Font = New System.Drawing.Font(ComboBox1.SelectedItem.ToString, 25, FontStyle.Regular)
End Sub
End Class
Thanks For your Help Sparrow.......
Re: How to Get Font Name and it's Own Styles.?
Quote:
Originally Posted by
jmcilhinney
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:
Dim availableStyles As List(Of FontStyle)
If myFontFamily.IsStyleAvailable(FontStyle.Bold) Then
availableStyles.Add(FontStyle.Bold)
End If
If myFontFamily.IsStyleAvailable(FontStyle.Italic) Then
availableStyles.Add(FontStyle.Italic)
End If
If myFontFamily.IsStyleAvailable(FontStyle.Bold Or FontStyle.Italic) Then
availableStyles.Add(FontStyle.Bold Or FontStyle.Italic)
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
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?
Re: How to Get Font Name and it's Own Styles.?
Quote:
Originally Posted by
medsont
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.
Re: How to Get Font Name and it's Own Styles.?
Re: How to Get Font Name and it's Own Styles.?
Quote:
Originally Posted by
jmcilhinney
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.:wave:
Re: How to Get Font Name and it's Own Styles.?
Quote:
Originally Posted by
medsont
Yes i know that but i say Thanks for him bcz he spend his time for my questions thats all.:wave:
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?
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.