VB放大缩小图片与图片的滚动显示

2025-11-21 23:36:55

1、“图片放大”对应command1,“图片缩小”对应command2,在frame1中放置image1、vscroll1、hscroll1,在vscroll1与hscroll1的交接处放置command3。

2、运行的效果:

VB放大缩小图片与图片的滚动显示

3、具体参考代码

‘为了例子的简易,设置image1的stretch设置为true,设置刚加载的image1的height为4000、width为4500,滚动条的单击进度为4,图片放大缩小倍数为2成

Private Sub Form_Load()

    Image1.Picture = LoadPicture("1.jpg")

    VScroll1.Visible = False

    HScroll1.Visible = False

    Command3.Visible = False

   

    VScroll1.Max = 4000

    VScroll1.LargeChange = 4000 / 4

    VScroll1.SmallChange = 4000 / 4

   

    HScroll1.Max = 4500

    HScroll1.LargeChange = 4500 / 4

    HScroll1.SmallChange = 4500 / 4   

End Sub

Private Sub Command1_Click()

    Image1.Height = Image1.Height * 1.2

    Image1.Width = Image1.Width * 1.2

    If Image1.Height > 4000 Then

        VScroll1.Visible = True

        HScroll1.Visible = True

        Command3.Visible = True

    End If

End Sub

Private Sub Command2_Click()  

    Image1.Height = Image1.Height * 0.8

    Image1.Width = Image1.Width * 0.8

    If Image1.Height < 4000 Then

        VScroll1.Visible = False

        HScroll1.Visible = False

        Command3.Visible = False

    End If

End Sub


Private Sub VScroll1_Change()

new_height = Image1.Height

next_height = new_height - 4000

Image1.Top = -(VScroll1.Value / 4000) * next_height

End Sub

Private Sub VScroll1_Scroll()

new_height = Image1.Height

next_height = new_height - 4000 

Image1.Top = -(VScroll1.Value / 4000) * next_height

End Sub

Private Sub hScroll1_Change()

new_width = Image1.Width

next_width = new_width - 4500

Image1.Left = -(HScroll1.Value / 4500) * next_width

End Sub

Private Sub hScroll1_Scroll()

new_width = Image1.Width

next_width = new_width - 4500

Image1.Left = -(HScroll1.Value / 4500) * next_width

End Sub

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢