Option Explicit Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongDim r() As RECT Dim mywnd As RECTPrivate Sub Form_Load() Dim i As Integer Dim j As Integer
i = Me.Controls.Count - 1 ReDim r(0 To i) GetWindowRect Me.hwnd, mywnd For j = 0 To i GetWindowRect Me.Controls(j).hwnd, r(j) Next jEnd SubPrivate Sub Form_Resize() If Me.WindowState = 1 Then Exit Sub End If Dim i As Integer Dim j As Integer Dim w As Integer Dim h As Integer
w = mywnd.Right - mywnd.Left h = mywnd.Bottom - mywnd.Top
i = Me.Controls.Count - 1 For j = 0 To i SetWindowPos Me.Controls(j).hwnd, 0, (r(j).Left - mywnd.Left) * Me.ScaleWidth / w / 15, (r(j).Top - mywnd.Top) * Me.ScaleHeight / h / 15, (r(j).Right - r(j).Left) * Me.ScaleWidth / w / 15, (r(j).Bottom - r(j).Top) * Me.ScaleHeight / h / 15, 0 Next j End Sub
有具体实现的程序吗
应该是该调用API函数吧
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongDim r() As RECT
Dim mywnd As RECTPrivate Sub Form_Load()
Dim i As Integer
Dim j As Integer
i = Me.Controls.Count - 1
ReDim r(0 To i)
GetWindowRect Me.hwnd, mywnd
For j = 0 To i
GetWindowRect Me.Controls(j).hwnd, r(j)
Next jEnd SubPrivate Sub Form_Resize()
If Me.WindowState = 1 Then
Exit Sub
End If
Dim i As Integer
Dim j As Integer
Dim w As Integer
Dim h As Integer
w = mywnd.Right - mywnd.Left
h = mywnd.Bottom - mywnd.Top
i = Me.Controls.Count - 1
For j = 0 To i
SetWindowPos Me.Controls(j).hwnd, 0, (r(j).Left - mywnd.Left) * Me.ScaleWidth / w / 15, (r(j).Top - mywnd.Top) * Me.ScaleHeight / h / 15, (r(j).Right - r(j).Left) * Me.ScaleWidth / w / 15, (r(j).Bottom - r(j).Top) * Me.ScaleHeight / h / 15, 0
Next j
End Sub
编译出错