VB .NET-左侧的全文对齐标题表格

时间:2018-08-26 20:34:13

标签: vb.net forms alignment title

我有这段代码来对齐表单的标题,但是我不能完全对齐它,当我给它留一个空格使其完全离开时,它可以工作,但最后增加了3个点,有人对修复有任何想法吗?这个吗?

表格固定单式

谢谢大家的时间

Private Sub ALINHAMENTO()

    Dim g As Graphics = Me.CreateGraphics()
    Dim startingPoint As Double = (Me.Width / 2) - (g.MeasureString(Me.Text.Trim, Me.Font).Width / 2)
    Dim widthOfASpace As Double = g.MeasureString(" ", Me.Font).Width
    Dim tmp As String = " "
    Dim tmpWidth As Double = 0

    Do
        tmp += " "
        tmpWidth += widthOfASpace
    Loop While (tmpWidth + widthOfASpace) < startingPoint

    Me.Text = Me.Text.Trim & tmp

End Sub

RUNNING

基于以下想法的解决方案:Olivier Jacot-Descombes

Private Sub ALINHAMENTO()

    Dim g As Graphics = Me.CreateGraphics()
    Dim startingPoint As Double = (Me.Width / 1.3) - (g.MeasureString(Me.Text.Trim, Me.Font).Width / 1)
    Dim widthOfASpace As Double = g.MeasureString(" ", Me.Font).Width
    Dim tmp As String = " "
    Dim tmpWidth As Double = 0

    Do
        tmp += " "
        tmpWidth += widthOfASpace
    Loop While (tmpWidth + widthOfASpace) < startingPoint

    Me.Text = Me.Text.Trim & tmp

End Sub

0 个答案:

没有答案