|
'-函数名称: FormAutoResize
'-功能描述: 当对窗体大小进行调节后自动调节窗体中的控件大小以适应窗体
'-输入参数: Form 必需的,应用到的窗体对象
' CltInit 必需的,用来保存初始尺寸的集合,模块级变量
' Initialized 必需的,初始化标志符,模块级变量
' DatasheetFontHeight 可选的,初始数据表视图字号
'-返回参数: 无
'-使用示例: FormAutoResize Me,mcltInit,mInitialized
'-使用注意: 使用时需要在窗体的类模块中声明两个模块级变量:
' Private mcltInit As New Collection
' Private mInitialized As Boolean
' 然后在窗体的Form_Resize事件过程中如示例那样调用此函数,如果包含子窗体,需要在子窗体引用的窗体中
' 同样进行调用
'-兼 容 性: Access 97及以上版本
'-参考资料:
'-作 者: 红尘如烟
'-创建日期; 2009-3-15
'===================================================================================================================
Function FormAutoResize(ByRef Form As Form, _
ByRef CltInit As Collection, _
ByRef Initialized As Boolean, _
Optional DatasheetFontHeight As Integer = 9)
On Error Resume Next
Dim ctl As Control
Dim SX As Single
Dim SY As Single
Screen.ActiveForm.Painting = False
If Not Initialized Then
CltInit.Add Form.InsideWidth, "Form_InsideWidth"
CltInit.Add Form.InsideHeight, "Form_InsideHeight"
CltInit.Add Form.Section(0).Height, "Form_Section0_Height"
CltInit.Add Form.Section(1).Height, "Form_Section1_Height"
CltInit.Add Form.Section(2).Height, "Form_Section2_Height"
Form.RowHeight = True
Form.DatasheetFontHeight = DatasheetFontHeight
CltInit.Add Form.DatasheetFontHeight, "Form_DatasheetFontHeight"
For Each ctl In Form.Controls
CltInit.Add ctl.Left, ctl.Name & "_L"
CltInit.Add ctl.Top, ctl.Name & "_T"
CltInit.Add ctl.Width, ctl.Name & "_W"
CltInit.Add ctl.Height, ctl.Name & "_H"
CltInit.Add ctl.FontSize, ctl.Name & "_F"
Next
Initialized = True
Else
SX = Form.InsideWidth / CltInit("Form_InsideWidth")
SY = Form.InsideHeight / CltInit("Form_InsideHeight")
Select Case Form.CurrentView
Case 1
Form.Section(0).Height = CltInit("Form_Section0_Height") * SY
Form.Section(1).Height = CltInit("Form_Section1_Height") * SY
Form.Section(2).Height = CltInit("Form_Section2_Height") * SY
For Each ctl In Form.Controls
ctl.Left = CltInit(ctl.Name & "_L") * SX
ctl.Top = CltInit(ctl.Name & "_T") * SY
ctl.Width = CltInit(ctl.Name & "_W") * SX
ctl.Height = CltInit(ctl.Name & "_H") * SY
ctl.FontSize = CltInit(ctl.Name & "_F") * SY
Next
Case 2
Form.DatasheetFontHeight = CltInit("Form_DatasheetFontHeight") * SY
For Each ctl In Form.Controls
ctl.ColumnWidth = -2
Next
End Select
End If
Form.Section(0).Height = CltInit("Form_Section0_Height") * SY
Form.Section(1).Height = CltInit("Form_Section1_Height") * SY
Form.Section(2).Height = CltInit("Form_Section2_Height") * SY
Screen.ActiveForm.Painting = True
Set ctl = Nothing
End Function
|
|