Results 1 to 7 of 7

Thread: Picture Box Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    7

    Exclamation Picture Box Question

    I was looking at the following

    http://www.vbworld.com/graphics/tip49.html

    and its exactly what i need execpt i want it to scroll a image from the left and then stop when it reachs the end of th image.
    If anyone knows please let me know

    Thanks

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    The easiest way to do it is to have two picture boxes.

    picContainer
    picImage

    add a scroll bar inside picContainer
    paste picImage inside picContainer and then measure the difference between the size of the two boxes.

    This is air code, so it may not be exactly right, but it should get you close

    Sub SetupPictureBoxes
    dim iPicWidth as integer
    dim iContainerWidth as integer
    dim iDifference as integer

    iPicWidth=picImage.Width
    iContainerWidth=picContainer.Width

    idifference=iContainerWidth-iPicWidth

    if iDifference>0 then
    hscroll1.Max=iDifference
    hscroll1.enabled=true
    else
    hscroll1.max=0
    hscroll1.enabled=false
    end if

    end sub

    Sub hscroll1_scroll
    ' subtract the value of hscroll to move the picture box
    picImage.left= - hscroll1.value
    end sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    7
    Thanks for that!

    But.... ( theres always a but )

    Iam trying to make it so there is no scroll bars that the image inside the picture box starts scrolling to the left when the page loads. Is there a better way to do this then using picture boxes ?

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Take a look at this post. The code I posted here is for scrolling text in a picture box, but you should be able to modify it to scroll an Image instead.

    If not, let me know and I'll play around with it.

    http://www.vbforums.com/showthread.p...olling+Picture

  5. #5
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    If you just want it to scroll across the form, you can use one picture box and a timer control. If you don't want to use a picturebox at all, you'll have to use API blitting functions. There is a lot of info on the net about blitting with VB. I don't know much about it. I just copy code when I need it.

    ' Set the timer interval to whatever makes the picture move at the desired rate

    More air code

    Sub Timer1_Timer
    ' This will make the picture move back and forth
    Static fMoveRight as boolean

    with picture1
    if fMoveRight then
    if (.Left + .Width) < Form1.Scalewidth then
    .Left=.Left + 1 ' change the movement amount if needed
    else
    fmoveright=false ' change direction
    end if
    else
    if .left>0 then
    .left=.left -1
    else
    fmoveright=true
    end if
    end with

    end sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2002
    Posts
    7
    Thanks hack for that

    Cafeenman, that code was good and worked well but it moved the picture box not the image inside the box. Is there any way you could change this to make it move the image. I would be greatful.

    Sub Timer1_Timer()
    Static fMoveLeft As Boolean

    With Picture1
    If fMoveLeft Then
    If (.Left + .Width) < Form1.ScaleWidth Then
    .Left = .Left - 1
    Else
    fMoveLeft = False
    End If
    Else
    fMoveLeft = True
    End If
    End With
    End Sub

  7. #7
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    You have to use API's if you want to manipulate a picture without the picture box. You can find that info by looking for bitblt and visual basic on the web. I don't know how to do it.

    If it's just the border of the picture box you find objectionable, you can turn it off so it just looks like a picture. It does use more resources, however.

    I don't do much work with bitmap manipulation, so I can't really help you more than that. Sorry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width