|
今天在翻阅桂思强老师的一本书时,看到了下面的代码,使窗体在不同分辩率下控件居中显示.现写下来与大家分享:
我们假设窗体中有一个标签:Label0,在窗体加载事件中写下如下代码:
Private Sub Form_Load() Dim rec As Rect DoCmd.Maximize GetWindowRect Me.hwnd, rec Me![Label0].Left = ((rec.Right / 2) * 14.9) - (Me![Label0].Width / 2) End Sub
在模块中写下如下代码:
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long Public Type Rect Left As Long Top As Long Right As Long Bottom As Long End Type
|