获取特定字体的所有样式 [英] Get all styles for a specific font
问题描述
我知道这是一个不时出现的老问题/问题,并提供了解决方案(WPF).不幸的是,我的知识WPF级别为空-我的请求是提供一些有关如何使用经典Windows解决此问题的提示/示例 表单应用程序(.NET).意思是,已安装的家族字体具有多种样式(例如Bookman Old Style家族具有4种样式:粗体,粗体斜体,浅色和浅斜体)-我要列举的是这4种字体,它们的文件名,然后使用他们 (在富文本框中格式化一些示例字符串)-总结起来,就像可以访问FontDialog控件后面的代码一样
I know it's an old question/problem flying around from time to time and a solution (WPF) was provided. Unfortunately, my knowledge WPF level is null - my kindly request is to have some hints/example about how to solve this problem using the classic Windows Form App (.NET). Means, having an installed family font with multiple styles (for example Bookman Old Style family has 4 styles: bold, bold italic, light and light italic) - what I want is to enumerate all this 4 fonts, their file names and then to use them (formatting some sample strings in a richtextbox) - summarizing, it's like to have access to the code behind a FontDialog Control
在此先感谢您的帮助
Danny Costa
Danny Costa
推荐答案
这是一个基本的开始.您可以添加更多样式选项等.
Here is a basic start. You can add more style options etc.
Imports System.Drawing.Text
Public Class Form4
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim f As Font
Dim FontList As New List(Of Font)
Dim installed_fonts As New InstalledFontCollection
Dim font_families() As FontFamily = installed_fonts.Families()
For Each font_family As FontFamily In font_families
If font_family.IsStyleAvailable(FontStyle.Regular) Then
f = New Font(font_family, 14, FontStyle.Regular)
FontList.Add(f)
End If
If font_family.IsStyleAvailable(FontStyle.Bold) Then
f = New Font(font_family, 14, FontStyle.Bold)
FontList.Add(f)
End If
If font_family.IsStyleAvailable(FontStyle.Italic) Then
f = New Font(font_family, 14, FontStyle.Italic)
FontList.Add(f)
End If
Next font_family
For Each f In FontList
RichTextBox1.SelectionFont = New Font(f.FontFamily, 12, f.Style)
RichTextBox1.AppendText(f.FontFamily.Name & " " & f.Style.ToString & vbLf)
Next
End Sub
End Class
这篇关于获取特定字体的所有样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!