返回列表 上一主題 發帖

Excel VBA 如何自動調整表單大小

回復 1# Jared
提供一個方法,根據表單的複雜度,效果可能不一定很好,供你參考:
在該表單的程式碼加上下面Code,開啟表單後,在表單上按:
Ctrl+滑鼠左鍵拖曳向上,可放大表單
Ctrl+滑鼠左鍵拖曳向下,可縮小表單
  1. Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  2.   Static lastY As Single
  3.   
  4.   If Button = 1 And Shift = 2 Then
  5.     If Y - lastY > 5 Then
  6.       ResizeUserform 1.1
  7.       lastY = Y
  8.     ElseIf lastY - Y > 5 Then
  9.       ResizeUserform 0.9
  10.       lastY = Y
  11.     End If
  12.   End If
  13. End Sub

  14. Private Sub ResizeUserform(dSizeCoeff As Double)
  15.   Dim c  
  16.   With Me
  17.     .Width = .Width * dSizeCoeff
  18.     .Height = .Height * dSizeCoeff
  19.    
  20.     For Each c In .Controls
  21.       With c
  22.         .Top = .Top * dSizeCoeff
  23.         .Left = .Left * dSizeCoeff
  24.         .Width = .Width * dSizeCoeff
  25.         .Height = .Height * dSizeCoeff
  26.         
  27.         On Error Resume Next
  28.         .Font.Size = .Font.Size * dSizeCoeff
  29.         On Error GoTo 0
  30.       End With
  31.     Next
  32.   End With
  33. End Sub
複製代碼

TOP

回復 3# GBKEE
太好了,我還一直在想操作太多次字型可能會變掉。
還原是個好主意!

TOP

        靜思自在 : 君子立恆志,小人恆立志。
返回列表 上一主題