--µ±´°Ìå´óС¸Ä±äʱ£¬ÈçºÎ¶¯Ì¬µÄ¸Ä±ä¿Ø¼þµÄ´óСÊÇÐí¶àVB³ÌÐòԱͷʹµÄÊ¡£ÓеÄÈËÉèÖô°ÌåResizableµ«È´²»¸Ä±ä¿Ø¼þµÄ´óС£»ÓеÄÈËÔò¸ù¾Ý¿Ø¼þµÄ¾ø¶ÔλÖÃÓë´°¿Ú´óСÏà¼Ó¼õµÄ°ì·¨À´ÖØж¨Î»¿Ø¼þÓë¸Ä±ä´óС£¬ÕâÖÖ°ì·¨±È½Ï·±Ëö£¬ÇÒ²»¿ÉÖØÓ㻵±È»Ò²ÓÐÈËÔòÏÞ¶¨´°¿Ú¸É´à²»Èøı䡣ÓÐûÓÐÒ»ÖÖ¼ò±ãÒ×Ðеİ취£¿´ð°¸Êǿ϶¨µÄ£¬ÏÂÃæ¸ø³öÒ»¸öÒ»ÀÍÓÀÒݵİ취£¬Ô´³ÌÐòÈçÏÂ:
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
`°´±ÈÀý¸Ä±ä±íµ¥ÄÚ¸÷Ôª¼þµÄ´óС£¬
ÔÚµ÷ÓÃReSizeFormÇ°Ïȵ÷ÓÃReSizeInitº¯Êý
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
Private Sub Form_Load()
Call ResizeInit(Me) `ÔÚ³ÌÐò×°Èëʱ±ØÐë¼ÓÈë
End Sub
Private Sub Form_Resize()
Call ResizeForm(Me) `È·±£´°Ìå¸Ä±äʱ¿Ø¼þËæÖ®¸Ä±ä
End Sub
----±¾ÀýÖиø³öÁ˶þ¸öº¯Êý:ResizeInitºÍResizeForm,ÔÚµ÷ÓÃResizeForm֮ǰ±ØÐëÏȵ÷ÓÃResizeInit¡£Äã¿ÉÒÔ½«±¾³ÌÐò¿½µ½´°Ìå´úÂë¶ÎÀȻºóÔÚ´°ÌåÀï¼ÓÈëÈÎÒâ¿Ø¼þ¼´¿É½øÐвâÊÔ