运行后,用鼠标拖动窗体边框,窗体上的控件被覆盖,希望自动增加滚动条,怎么实现?
运行后,用鼠标拖动窗体边框,窗体大小改变,窗体上的控件被覆盖,希望自动增加滚动条,怎么实现?
[解决办法]
对 增加一个容器! 把你的控件都放到容器中 我们改变容器显示的位置就好了
请楼主按照步骤做这个例题!
1.新建立一个exe
2.向窗体内拖动如下东西
1个图片框
1个水平滚动条
1个垂直滚动条
3.随意把一些控件放到图片框里[一定要把一些东西放到 图片框 内 这个图片框是容器 装控件的]
4.复制如下代码到代码窗口 然后运行看效果! -_- 这个可是花了好些时间想的
=============================================================
Private Sub Form_Load()
HScroll1.Width = Picture1.Width
HScroll1.Left = 0
VScroll1.Top = 0
VScroll1.Height = Picture1.Height
Me.Width = 10500
Me.Height = 7500
Picture1.Left = 0
Picture1.Top = 0
Picture1.Width = 9000
Picture1.Height = 6000
Picture1.BackColor = vbBlack
End Sub
Private Sub Form_Resize()
Call 窗体改变大小
Call 窗体改变大小
End Sub
Private Sub 窗体改变大小()
If Me.Width < Picture1.Width + 120 Then
HScroll1.Visible = True
HScroll1.Max = Picture1.Width - Me.Width - 15
HScroll1.Width = Me.Width - 100
HScroll1.Top = Me.Height - 750
If VScroll1.Visible = True Then
HScroll1.Width = Me.Width - 350
Else
Picture1.Left = 0
HScroll1.Width = Me.Width - 100
End If
Else
HScroll1.Visible = False
End If
If Me.Height < Picture1.Height + 480 Then
VScroll1.Visible = True
VScroll1.Max = Picture1.Height - Me.Height + 30
VScroll1.Height = Me.Height - 500
VScroll1.Left = Me.Width - 380
Else
Picture1.Top = 0
VScroll1.Visible = False
End If
End Sub
Private Sub HScroll1_Change()
Picture1.Left = 0 - HScroll1.Value
'MsgBox "滚动条的值= " & HScroll1.Value & " 图片框的left= " & Picture1.Left & " 滚动条的最大值 " & HScroll1.Max
End Sub
Private Sub VScroll1_Change()
Picture1.Top = 0 - VScroll1.Value
'MsgBox "滚动条的值= " & VScroll1.Value & " 图片框的left= " & Picture1.Top & " 滚动条的最大值 " & VScroll1.Max
End Sub
===================================================
cike技术交流群 16874787 论坛支持:http://www.hexi5.com/bbs
有问题可以到群里找我!