窗體自動(dòng)居中代碼
使窗體居中顯示代碼
access中的窗體雖然設(shè)置了自動(dòng)居中,但是打開后總是有點(diǎn)不居中的感覺,加下如下代碼可以做到真正居中顯示
Private Sub Form_Load()
DoCmd.Echo False
Dim x, y As Integer
DoCmd.Maximize
x = Me.WindowWidth
y = Me.WindowHeight
DoCmd.Restore
DoCmd.Echo True
Move (x - Me.WindowWidth) / 2, (y - Me.WindowHeight) / 2
End Sub
下列代碼適用于accessXP以上
'使用方法:
'Private Sub Form_Load()
' moveFormToCenter Me '居中
'End Sub
'Private Sub Form_Load()
' moveFormToCenter Me, 3000, 2000 '調(diào)整窗體大小并居中
'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
'狀態(tài)欄高: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為測(cè)試微調(diào)值
lngW = lngW * 15
lngH = GetaccessClientHeight() - 4 '-4為測(cè)試微調(diào)值
'lngH = lngH - (22 * 1) '一個(gè)菜單欄
lngH = lngH - (26 * 1) '一個(gè)工具欄
'lngH = lngH - (20 * 1) '一個(gè)狀態(tài)欄
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
(責(zé)任編輯:admin)
- ·Access窗體居中顯示技巧
- ·Access中Tab鍵的使用說明【技巧】
- ·Access粘貼對(duì)象到Tab選卡上的技巧
- ·Access在窗體上顯示當(dāng)前記錄和總記錄數(shù)
- ·Access隱藏組合框的小箭頭
- ·Access窗體屬性表
- ·【技巧】Access選項(xiàng)組邊框變?yōu)閳A角邊框
- ·Access函數(shù)me.sfmsub.form 提示子窗體
- ·Access中使用縮放對(duì)話框顯示文本框文字
- ·access技巧-中文顯示星期幾的簡(jiǎn)單方法
- ·Access控件是否可見,可編輯,鎖定的技巧
- ·根據(jù)查找窗體設(shè)定的條件篩選主窗體的數(shù)
- ·父子窗體的語法介紹
- ·access實(shí)現(xiàn)組合框聯(lián)動(dòng)詳細(xì)教程
- ·Web Service在Access中的應(yīng)用技巧
- ·Access窗體最大化,最小化等操作