標題:
[發問]
請教表單內 Label 上下左右置中問題
[打印本頁]
作者:
mark15jill
時間:
2012-11-23 16:59
標題:
請教表單內 Label 上下左右置中問題
網路上找到有人分享 Label字串置中(上下左右),但是該原始碼似乎只能用於單一物件。
有試著改寫,但顯示出來 僅水平置中
請問若以 迴圈來表示的話
該要如何修正比較恰當
[attach]13259[/attach]
Private Sub UserForm_Initialize()
Dim lab As MSForms.Label
Dim xx As Integer
Dim yy As Integer
With UserForm1
.Height = 500
.Width = 500
For yy = 1 To 500 Step 100
For xx = 1 To 500 Step 100
Set lab = .Controls.Add("forms.label.1")
With lab
'.Caption = .Name
.Top = 10 + yy
.Left = 10 + xx
.AutoSize = False
.BackColor = &HC0FFC0
Dim str As String
Dim strout As String
str = .Name
'strout = ""
.BorderStyle = fmBorderStyleSingle
.TextAlign = fmTextAlignCenter
.WordWrap = True
strout = .Name
.Caption = strout
End With
Next
Next
End With
End Sub
'以下是某網站的 LABEL 字串置中範例
' Dim str As String = "這裡放上您要的字"
' Dim strOut As String = ""
' Label1.BorderStyle = BorderStyle.FixedSingle
' Label1.TextAlign = ContentAlignment.TopCenter
' For Each ch As Char In str.ToCharArray
' strOut &= ch & ControlChars.CrLf
' Next
' Label1.Text = strOut
複製代碼
作者:
GBKEE
時間:
2012-11-26 15:45
回復
1#
mark15jill
試試看
With lab
.Top = 10 + yy
.Left = 10 + xx
.Font.Size = 12 '字型大小
.Height = .Font.Size + .Font.Size * 0.1 '調整高度
' .AutoSize = False
複製代碼
作者:
mark15jill
時間:
2012-11-26 16:13
本帖最後由 mark15jill 於 2012-11-26 16:17 編輯
回復
2#
GBKEE
GBKEE大大,謝謝。
這方法可以,但是,測試結果 僅限於 字體大小比較小的時候適用。
用大小 36 測試後,反而會有點往上偏。
[attach]13290[/attach]
作者:
GBKEE
時間:
2012-11-26 16:32
回復
3#
mark15jill
字型大於36
時可調整
0.1
試試看
.Height = .Font.Size + .Font.Size * 0.1 '調整高度
複製代碼
作者:
mark15jill
時間:
2012-11-26 16:59
回復
4#
GBKEE
剛試著修改視窗大小,沒改沒事情,改了變成...
[attach]13291[/attach]
<發現哪邊怪怪的了嗎?>
Private Sub UserForm_Initialize()
Dim lab As MSForms.Label
Dim xx As Integer
Dim yy As Integer
With UserForm1
.Height = 700
.Width = 1400
For yy = 1 To 700 Step 100
For xx = 1 To 1400 Step 200
Set lab = .Controls.Add("forms.label.1")
With lab
'.Caption = .Name
.Top = 10 + yy
.Left = 10 + xx
.AutoSize = False
.Font.Size = 36 '字型大小
.Height = .Font.Size + .Font.Size * 0.1 '調整高度
.Width = 100
.BackColor = &HC0FFC0
Dim str As String
Dim strout As String
str = .Name
'strout = ""
.BorderStyle = fmBorderStyleSingle
.TextAlign = fmTextAlignCenter
.WordWrap = True
strout = .Name
.Caption = strout
End With
Next
Next
End With
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)