窗体加入滚动条后怎么改变控件位置?
当窗体缩小后想要用滚动条滚动来显示其它控件,查到可以用这样的语句:
Private Sub VScroll1_Change()
For Each c In Form1.Controls
If c.Name <> "VScroll1" And c.Name <> "HScroll1" Then c.Top = c.Top - VScroll1.Value
Next
End Sub
Option Explicit
Private Sub Form_Load()
Picture1.Move 0, 0
With VScroll1
.Min = 0
.SmallChange = 120
End With
End Sub
Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then Exit Sub
On Error Resume Next
With VScroll1
.Move ScaleWidth - .Width, 0, .Width, ScaleHeight
If ScaleHeight >= Picture1.Height Then
.Max = 0
.Value = 0
Else
.Max = Picture1.Height - ScaleHeight
.SmallChange = 120
.LargeChange = ScaleHeight
End If
End With
On Error GoTo 0
End Sub
Private Sub VScroll1_Change()
Picture1.Top = -VScroll1.Value
End Sub