在CSDN上看到的一个问题的解决方案 贴在这里方便下次查询
运行后,用鼠标拖动窗体边框,窗体大小改变,窗体上的控件被覆盖,希望自动增加滚动条,怎么实现? 1.新建立一个exe 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 若picture控件显示的是一个大的图片 那么这个例题程序就可以显示局部图片了! |