|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
网上找到两段代码
1、以下代码可自由拉伸窗口大小,但窗口控件不会变化
#If VBA7 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowW" (ByVal lpClassName As LongPtr, _
ByVal lpWindowName As LongPtr) As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongW" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongW" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#Else
Private Declare Function FindWindow Lib "user32" Alias "FindWindowW" (ByVal lpClassName As Long, _
ByVal lpWindowName As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongW" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongW" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
Dim hWnd As Long
hWnd = FindWindow(StrPtr("ThunderDFrame"), StrPtr(Me.Caption))
SetWindowLong hWnd, -16, GetWindowLong(hWnd, -16) Or &H40000 Or &H20000 Or &H10000
2、以下代码可以实现控件随窗口大小变化,但窗口不可以自由调整大小
'Option Explicit
'Dim frmW, frmH
'Dim i
'
'Private Sub Form_Load()
'If WindowState <> vbMaximized Then
'frmW = Me.Width
'frmH = Me.Height
'End If
'For i = 0 To Ms1.Cols - 1
'Ms1.ColWidth(i) = Int((Ms1.Width - 360) / Ms1.Cols)
'Next
'End Sub
'
'Private Sub Form_Resize()
'On Error Resume Next
'If frmW = 0 Or frmH = 0 Then Exit Sub
'Dim c As Control, x, y
'x = Me.Width / frmW
'y = Me.Height / frmH
'For Each c In Me.Controls
'With c
'.Left = Int(.Left * x)
'.Top = Int(.Top * y)
'.Width = Int(.Width * x)
'.Height = Int(.Height * y)
'End With
'Next
'For i = 0 To Ms1.Cols - 1
'Ms1.ColWidth(i) = Int(Ms1.ColWidth(i) * x)
'Next
'frmW = Me.Width
'frmH = Me.Height
'End Sub
'Dim p As Object, x, y
'With Application
'.WindowState = xlMaximized
'x = .Width / Me.Width
'y = .Height / Me.Height
'For Each p In Me.Controls
'p.Move p.Left * x, p.Top * y, p.Width * x, p.Height * y
'Next
'Me.Move .Left, .Top, .Width, .Height
'End With
求大神把这两段代码综合写一下新代码,可自由拉伸窗口,窗口控件随窗口大小自动调整大小。
|
|