请教VB中一个窗体标题的问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 19:12:34
当窗体大小变化时,怎么能让它的caption文字始终处于中间呢?

从网上找的一段代码。好像是根据标题栏宽度加空格。
Dim oldsize As Long
Public Sub CenterC(frm As Form)
Dim SpcF As Integer 'How many spaces can fit
Dim clen As Integer 'caption length
Dim oldc As String 'old caption
Dim i As Integer 'notimportant
'remove any spaces at the ends of the caption
'very easy if your eadit carefully
oldc = frm.Caption

Do While Left(oldc, 1) = Space(1)
DoEvents
oldc = Right(oldc, Len(oldc) - 1)
Loop

Do While Right(oldc, 1) = Space(1)
DoEvents
oldc = Left(oldc, Len(oldc) - 1)
Loop

clen = Len(oldc)

If InStr(oldc, "!") <> 0 Then
If InStr(oldc, "") <> 0 Then
clen = clen * 1.5
Else
clen = clen * 1.4
End If
Else
If InStr(