有点深奥没看懂,能解释下吗?
Function ctlFontSize(ctl As Control)
Dim w As Single
Dim i As Long
Dim b As Boolean
ctl.FontSize = n
w = ctl.Width / 1440
For i = n To 1 Step -1
b = (Len(ctl.Value) + 1) * i / 72 - w <= 0
If b = True Then
ctl.FontSize = i
Exit For
End If
Next
End Function
ljwily 发表于 2011-11-12 19:46
有点深奥没看懂,能解释下吗?
Function ctlFontSize(ctl As Control)
Dim w As Single
Dim n As Long '存放字号的模块级公共变量
Private Sub Form_Load()
n = Me.电站名称.FontSize '将【电站名称】控件的字号赋值给模块级变量n
End Sub
Function ctlFontSize(ctl As Control)
Dim w As Single
Dim i As Long
Dim b As Boolean
ctl.FontSize = n '控件字号赋值为加载时【电站名称】的字号
w = ctl.Width / 1440 '控件宽度换算为英寸,存于w中。
For i = n To 1 Step -1 '按字号递减循环
b = (Len(ctl.Value) + 1) * i / 72 - w <= 0 '比较当前控件值的宽度是否超过控件宽度
If b = True Then
ctl.FontSize = i '如果控件值超宽,则控件字号减小一个字号。
Exit For
End If
Next
End Function