使窗體居中顯示代碼
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
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