我想将我的主表单文本与标题栏的中心对齐。我不知道我将如何开始。我也“用谷歌搜索”了这个问题,但没有找到解决方案。
问问题
6327 次
1 回答
1
这适用于我的评论链接中提到的警告:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
CenterMe()
End Sub
Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
CenterMe()
End Sub
Private Sub CenterMe()
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 = tmp & Me.Text.Trim & tmp
Me.Refresh()
End Sub
End Class
于 2013-06-05T16:38:15.793 回答