2

这是一个隔离我的问题的示例代码。我试图从右到左绘制一个字符串。如果我的字符串以数字开头,那么有一个逗号和一个字母,它会重新排列我的字符串。但是如果我写它时没有它的格式好的..打开一个新项目并添加此表格以自己查看..谢谢

Public Class Form1
    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        Dim myFont As Font = New Font("Zipper", 24, FontStyle.Bold)
        Dim myBrush As Brush = Brushes.Black
        Dim line1 As String = "220516,5130.02,N,00046.34,W,213.8,T,218.0,M,0004.6,N"
        Dim format As StringFormat = New StringFormat(StringFormatFlags.DirectionRightToLeft)
        Me.Width = 1400
        e.Graphics.DrawString(line1, myFont, myBrush, 1300, 0, format)
        e.Graphics.DrawString(line1, myFont, myBrush, 100, 50)
    End Sub
End Class
4

1 回答 1

3

尝试使用 Alignment 属性:

Dim format As New StringFormat
format.Alignment = StringAlignment.Far

你也没有处理你的字体对象。为此,一个简单的 Using 括号效果很好:

Using myFont As Font = New Font("Zipper", 24, FontStyle.Bold)
  Dim myBrush As Brush = Brushes.Black
  Dim line1 As String = "220516,5130.02,N,00046.34,W,213.8,T,218.0,M,0004.6,N"
  Dim format As New StringFormat
  format.Alignment = StringAlignment.Far
  Me.Width = 1400
  e.Graphics.DrawString(line1, myFont, myBrush, 1300, 0, format)
  e.Graphics.DrawString(line1, myFont, myBrush, 100, 50)
End Using
于 2013-07-24T14:50:25.417 回答