组合框下拉列表不显示特殊字符

时间:2019-04-03 11:05:06

标签: .net fonts combobox font-face true-type-fonts

Odd Combobox Behaviour我用包含特殊字符的城市名称填充了“组合框”中的项目。在下拉列表中,它们不能正确显示,但是当我选择一个时,它们可以正确显示

更新4: ComboBox是一个奇怪的字体问题(请参阅评论)

原始帖子:

这是我从XML文件填充组合框的方式:

Public Shared Sub PopulateCities()
    Dim strPath As String = System.IO.Path.GetDirectoryName(
        System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
    Dim ds As New DataSet
    Dim i As Integer
    ds.InferXmlSchema(Strings.Mid(strPath, 7) + "/cities.xml", Nothing)
    ds.ReadXml(Strings.Mid(strPath, 7) + "/cities.xml")
    If ds.Tables.Count > 0 Then
        Dim a As String
        For i = 0 To ds.Tables(0).Rows.Count - 1
            a = ds.Tables(0).Rows(i).Item("NOME")
            MainForm.LocationBox.Items.Add(a)
        Next
    End If
End Sub

列表中的项目必须与组合框中的当前项目显示相同的方式。

更新:

切换到系统字体时,不会出现问题,但是我需要使用自己的字体。 ComboBox using System Font

通过这种方式以编程方式分配字体:

  Public Shared pfc As PrivateFontCollection = New PrivateFontCollection()
  Dim strPath As String = System.IO.Path.GetDirectoryName(
            System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
  REM Loading Font files
        pfc.AddFontFile(Strings.Mid(strPath, 7) & "\magickfont.ttf")

  SetMagickFont(LocationBox)

  Public Sub SetMagickFont(obj As Object)
        Dim s As Single = obj.font.size
        Dim fs As FontStyle = obj.font.style
        obj.font = New Font(pfc.Families(0), s, fs)
        obj.invalidate
    End Sub

更新2:

保持字体并添加

MainForm.LocationBox.Items.Add("Zürich åäö")

获得相同的奇数结果。 Manually adding an item to ComboBox

0 个答案:

没有答案