带有DirectionRightToLeft的VB.net Graphics.DrawString混合了我的字符串

时间:2013-07-24 14:40:03

标签: vb.net

这是一个示例代码隔离我的problem.im试图从右到左绘制一个字符串..如果我的字符串以数字开头然后有一个字母逗号它重新排列我的字符串..但是如果我没有写它格式很好..打开一个新项目并添加此表单以便自己查看..谢谢

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

1 个答案:

答案 0 :(得分:2)

尝试使用Alignment属性:

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

您也没有处置您的字体对象。为此,一个简单的使用支架效果很好:

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