在vb中,我想通过picturebox控件或image控件浏览某文件夹下的所有jpg图片,通过两个按钮(“上一副图片”,“下一副图片”)来浏览,有两个问题:
1,怎么实现浏览图片的功能?
2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!

解决方案 »

  1.   

    //怎么实现浏览图片的功能set picture1.picture=loadpicture("c:\test.jpg")
    image控件类似//我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!可以,参考:http://community.csdn.net/Expert/topic/3263/3263473.xml?temp=.2826044
      

  2.   

    或者本文件夹下的文件可以通过dir函数或者filebox控件取得.
    直接使用image控件作为加载图片的控件,loadpicture函数.
    pciturebox作为容器,实现image控件在picturebox容器内的移动.那么就用滚动条实现.
      

  3.   

    //我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?使用滚动条可以吗?怎么使用滚动条来实现??谢谢!!!你试试image控件,设置stretch为true,可以以一定的大小显示
      

  4.   

    '一个简单的滚动条例子
    'Form1中放一个PictureBox:  Picture1
    'Picture1中放一个Image:    Image1
    '一个HScrollBar:           HScroll1
    '一个VScrollBar:           VScroll1Private Sub Form_Load()
        With Image1
            .Move 0, 0
            .Picture = LoadPicture("c:\windows\logow.sys")
            '如果这句出错,请改为其他的图片文件
            Picture1.Move 0, 0, .Width \ 2, .Height \ 2
        End With
        With Picture1
            HScroll1.Move 0, .ScaleHeight - 255, .ScaleWidth - 255, 255
            HScroll1.Max = .ScaleWidth + 255 + 255 \ 2
            HScroll1.LargeChange = .ScaleWidth / 50
            HScroll1.SmallChange = .ScaleWidth / 50
            VScroll1.Move .ScaleWidth - 255, 0, 255, .ScaleHeight - 255
            VScroll1.Max = .ScaleHeight + 255 + 255 \ 2
            VScroll1.LargeChange = .ScaleHeight / 50
            VScroll1.SmallChange = .ScaleHeight / 50
            Dim cmdMask As CommandButton
            Set cmdMask = Controls.Add("vb.commandbutton", "mask", Picture1)
            cmdMask.Move .ScaleWidth - 255, .ScaleHeight - 255, 255, 255
            cmdMask.Enabled = False
            cmdMask.Visible = True
        End With
    End SubPrivate Sub HScroll1_Change()
        Image1.Left = -HScroll1.Value
    End SubPrivate Sub VScroll1_Change()
        Image1.Top = -VScroll1.Value
    End Sub
      

  5.   

    Dim idx As Integer
    Private Sub Command1_Click()
    If idx >= 1 Then
    idx = idx - 1
    Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))End If
    End SubPrivate Sub Command2_Click()
    If idx < File1.ListCount - 2 Then
    idx = idx + 1
    Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))
    End If
    End SubPrivate Sub Dir1_Change()File1.Path = Dir1.Path
    File1.Refresh
    On Error GoTo chli:
    idx = 0
    Image1.Picture = LoadPicture(File1.Path & "\" & File1.List(idx))
    chli:
    Exit Sub
    End SubPrivate Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
    Dir1.Refresh
    End Sub
      

  6.   

    1,怎么实现浏览图片的功能?
    用楼上的方法,或使用pciturebox控件数组。
    2,我的picturebox控件或image控件大小是一定的,如果图片太大或太小的话怎么显示?
    使用:PaintPicture方法。对较大图片可以缩小,或只显示局部。
    Picture1.PaintPicture Picture,x1,y1,[width1],[height1],[x2],[y2],[width2],[height2],[opcode]
    说明:参数Picture为要绘制的图象或加载的图片
          x1,y1为图象或图片在控件上的位置,,[width1],[height1为图象或图片在控件上的高度或宽度。[width1],[height1 如果取负值,可以把图象或图片翻转显示。
           [x2],[y2]],[width2],[height2]四个参数可以指定只绘制图象或图片的局部。
          [opcode]参数指定绘制的方法,建议省略。
      

  7.   

    'add an image,two commandbutton to form1:Dim alljpgfile() As String, index As IntegerSub getallfile(ByVal mydir As String, ByRef x() As String)
    Dim fname As String, i As Integer
    If Right(mydir, 1) <> "\" Then mydir = mydir & "\"
    fname = Dir(mydir & "\*.jpg")
    i = 1
    Do While fname <> ""
    ReDim Preserve x(1 To i)
    x(i) = mydir & fname
    i = i + 1
    fname = Dir
    Loop
    End SubPrivate Sub Command1_Click()
    If index = UBound(alljpgfile) Then
    index = 1
    Else
    index = index + 1
    End If
    Image1.Picture = LoadPicture(alljpgfile(index))
    End SubPrivate Sub Command2_Click()
    If index = 1 Then
    index = UBound(alljpgfile)
    Else
    index = index - 1
    End If
    Image1.Picture = LoadPicture(alljpgfile(index))
    End SubPrivate Sub Form_Load()
    Command1.Caption = "prev"
    Command2.Caption = "next"
    index = 1
    Image1.Stretch = True
    getallfile "C:\Documents and Settings\hsy\My Documents\My Pictures", alljpgfile
    Image1.Picture = LoadPicture(alljpgfile(index))
    End Sub