窗体自动居中,适用于accessXP以上
时 间:2004-11-15 00:00:00
作 者:黄海 ID:32 城市:苏州
摘 要:窗体自动居中,适用于ACCESSXP以上
正 文:
'Private Sub Form_Load()
' moveFormToCenter Me '居中
'End Sub
'Private Sub Form_Load()
' moveFormToCenter Me, 3000, 2000 '调整窗体大小并居中
'End Sub
Option Compare Database
Option Explicit
Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
Public Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
'菜单栏高:22
'工具栏高:26
'状态栏高:20
Public Function moveFormToCenter(ByRef Frm As Form, Optional ByVal longFormWidth As Long = 0, Optional ByVal longFormHeight As Long = 0)
Dim lngW, lngH As Long
lngW = GetAccessClientWidth() - 4 '-4为测试微调值
lngW = lngW * 15
lngH = GetAccessClientHeight() - 4 '-4为测试微调值
'lngH = lngH - (22 * 1) '一个菜单栏
lngH = lngH - (26 * 1) '一个工具栏
'lngH = lngH - (20 * 1) '一个状态栏
lngH = lngH * 15
If longFormWidth + longFormHeight = 0 Then
Frm.Move (lngW - Frm.WindowWidth) / 2, (lngH - Frm.WindowHeight) / 2
End If
If longFormWidth > 0 And longFormHeight > 0 Then
Frm.Move (lngW - longFormWidth) / 2, (lngH - longFormHeight) / 2, longFormWidth, longFormHeight
End If
End Function
Public Function GetAccessClientWidth() As Integer
Dim R As RECT
Dim hwnd As Long
Dim RetVal As Long
hwnd = Application.hWndAccessApp
RetVal = GetClientRect(hwnd, R)
'Debug.Print R.x2
'Debug.Print R.x1
GetAccessClientWidth = R.x2 - R.x1
End Function
Public Function GetAccessClientHeight() As Integer
Dim R As RECT
Dim hwnd As Long
Dim RetVal As Long
hwnd = Application.hWndAccessApp
RetVal = GetClientRect(hwnd, R)
'Debug.Print R.y2
'Debug.Print R.y1
GetAccessClientHeight = R.y2 - R.y1
End Function
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- Inputbox输入密码打开查...(12.23)
- 【Access Dsum示例】...(12.16)
- Inputbox输入密码打开窗...(12.13)
- 【Access DCount示...(12.02)

学习心得
最新文章
- 用Access查询语句如何得到前3...(02.17)
- Access快速开发平台--导入导...(02.14)
- 按回车键后光标移动到下一条记录的V...(02.12)
- Access快速开发平台--要实现...(02.10)
- Access快速开发平台--让Pe...(02.08)
- 【Access Dsum示例】用D...(02.07)
- Access对子窗体的数据进行平均...(02.05)
- Access快速开发平台附件上传,...(01.18)
- 【IIF函数示例】用iif函数判断...(01.18)
- Access快速开发平台--如何获...(01.17)