【发布时间】:2016-11-29 12:41:38
【问题描述】:
使用 iTextSharp 创建 PDF 我需要让用户选择字体,但对最小和最大大小以及一些字体列表有限制,也许是我将添加到程序的资源文件夹中的字体列表
有没有办法将字体对话框设置为仅显示一组个性化的字体?例如 myapppath/resources 文件夹中的字体?
Dim myFont, mySize As String
Using dlg As New frmFonts
dlg.FontMustExist = True
dlg.MinSize = 9
dlg.MaxSize = 14
dlg.ShowEffects = False
If dlg.ShowDialog <> DialogResult.Cancel Then
myFont = dlg.Font.Name
mySize = dlb.Font.Size
End If
End Using
@Tyler 建议的尝试解决方案
下面是从 C# 到 VB.NET 的自动转换代码
我在标有 ** 的行上遇到错误
错误 1) 'FontListBox' 类型的值无法转换为 'Control'
错误2) 转换运算符不能从一个类型转换为相同类型
Partial Public Class MyFontDialog
Inherits Form
Private _fontListBox As FontListBox
Private _fontSizeListBox As ListBox
Public Sub New()
'InitializeComponent();
_fontListBox = New FontListBox()
AddHandler _fontListBox.SelectedIndexChanged, AddressOf OnfontListBoxSelectedIndexChanged
_fontListBox.Size = New Size(200, Height)
**Controls.Add(_fontListBox)**
_fontSizeListBox = New ListBox()
**_fontSizeListBox.Location = New Point(_fontListBox.Width, 0)**
Controls.Add(_fontSizeListBox)
End Sub
Private Sub OnfontListBoxSelectedIndexChanged(sender As Object, e As EventArgs)
_fontSizeListBox.Items.Clear()
**Dim font As Font = TryCast(_fontListBox.SelectedItem, Font)**
If font IsNot Nothing Then
For Each style As FontStyle In [Enum].GetValues(GetType(FontStyle))
If font.FontFamily.IsStyleAvailable(style) Then
_fontSizeListBox.Items.Add(style)
End If
Next
End If
End Sub
End Class
Friend Class FontListBox
Friend Size As Size
Public Event SelectedIndexChanged(sender As Object, e As EventArgs)
**Public Shared Widening Operator CType(v As FontListBox) As FontListBox**
Throw New NotImplementedException()
End Operator
End Class
【问题讨论】:
标签: vb.net