'*********************** 窗体大小改变后,所有控件的大小都会随之变化 '**** **** 不用一个一个的控制调整 '**** ResizeFrm.bas **** '**** **** '***********************Attribute VB_Name = "Module1" Option Explicit Private FormOldWidth As Long '保存窗体的原始宽度 Private FormOldHeight As Long '保存窗体的原始高度'在调用ResizeForm前先调用本函数 Public Sub ResizeInit(FormName As Form) Dim Obj As Control FormOldWidth = FormName.ScaleWidth FormOldHeight = FormName.ScaleHeight On Error Resume Next For Each Obj In FormName Obj.Tag = Obj.Left & " " & Obj.Top & " " _ & Obj.Width & " " & Obj.Height & " " Next Obj On Error GoTo 0 End Sub Public Sub ResizeForm(FormName As Form) Dim Pos(4) As Double Dim i As Long, TempPos As Long, StartPos As Long Dim Obj As Control Dim ScaleX As Double, ScaleY As Double ScaleX = FormName.ScaleWidth / FormOldWidth '保存窗体宽度缩放比例 ScaleY = FormName.ScaleHeight / FormOldHeight '保存窗体高度缩放比例 On Error Resume Next For Each Obj In FormName StartPos = 1 For i = 0 To 4 '读取控件的原始位置与大小 TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare) If TempPos > 0 Then Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos) StartPos = TempPos + 1 Else Pos(i) = 0 End If '根据控件的原始位置及窗体改变大小的比例对控件重新定位与改变大小 Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, _ Pos(2) * ScaleX, Pos(3) * ScaleY Next i Next Obj On Error GoTo 0 End Sub
If Me.WindowState = 0 Then
Text1.Width = Me.Width - 200
Text1.Height = Me.Height - 200
End If
End Sub
能交个朋友吗?有一些vb的问题交流一下。呵呵!你的qq是多少
Text1.top=me.scaltop
Text1.height=me.scalheight
Text1.width=me.scalheight
应该是:me.scalWIDTH才对
'**** **** 不用一个一个的控制调整
'**** ResizeFrm.bas ****
'**** ****
'***********************Attribute VB_Name = "Module1"
Option Explicit
Private FormOldWidth As Long
'保存窗体的原始宽度
Private FormOldHeight As Long
'保存窗体的原始高度'在调用ResizeForm前先调用本函数
Public Sub ResizeInit(FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & " " & Obj.Top & " " _
& Obj.Width & " " & Obj.Height & " "
Next Obj
On Error GoTo 0
End Sub
Public Sub ResizeForm(FormName As Form)
Dim Pos(4) As Double
Dim i As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double ScaleX = FormName.ScaleWidth / FormOldWidth
'保存窗体宽度缩放比例
ScaleY = FormName.ScaleHeight / FormOldHeight
'保存窗体高度缩放比例
On Error Resume Next
For Each Obj In FormName
StartPos = 1
For i = 0 To 4
'读取控件的原始位置与大小 TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)
If TempPos > 0 Then
Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos(i) = 0
End If
'根据控件的原始位置及窗体改变大小的比例对控件重新定位与改变大小
Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, _
Pos(2) * ScaleX, Pos(3) * ScaleY
Next i
Next Obj
On Error GoTo 0
End Sub