gpt4 book ai didi

VB.net Graphics.DrawString 方向从右到左混淆了我的字符串

转载 作者:行者123 更新时间:2023-12-04 04:48:20 25 4
gpt4 key购买 nike

这是一个隔离我的问题的示例代码。我试图从右到左绘制一个字符串。如果我的字符串以数字开头,然后有一个带字母的逗号,它会重新排列我的字符串。很好..打开一个新项目并添加此表单以供您自己查看..谢谢

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

最佳答案

尝试使用 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

关于VB.net Graphics.DrawString 方向从右到左混淆了我的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17837257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com