Office中国论坛/Access中国论坛
标题: 窗中居中显示时,代码出错问题! [打印本页]
作者: LIXIANACCP 时间: 2006-3-9 00:07
标题: 窗中居中显示时,代码出错问题!
我想使A窗体在屏幕中居中显示!我在A窗体中的加载事件中,写下列代码(教科书这样说的),但运行时,显示"方法和数据成员未找到"的错误
Width 显示黄色! 问题在哪?Private Sub form_load()
Width = Screen.Width * 0.75
Height = Screen.Height * 0.75
Left = (Screen.Width - Width) / 2
Top = (Screen.Height - Height) / 2
End Sub
Width Height Screen 等名称不是系统保留字吗?
是否要人工定义设置,如要,在什么地方设置?
求教!
[此贴子已经被作者于2006-3-8 16:20:10编辑过]
作者: fan0217 时间: 2006-3-9 00:19
转贴:http://www.office-cn.net/forum.php?mod=viewthread&tid=35658&replyID=&skin=1
使用方法:
'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
作者: LIXIANACCP 时间: 2006-3-9 20:59
太复杂了!除此之外,就没简单一点的了吗?《VBA 6.0技术开发大全》怎么写得哪么简单呢?
[此贴子已经被作者于2006-3-9 12:59:29编辑过]
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) |
Powered by Discuz! X3.3 |