CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Posts
    24

    how to move images in a imagebox

    hi guys need a bit of help and with it being my first post on this site please be nice lol (just kidding)

    what i have is a image box which is loaded with one of several items from a resource file i have created and what i need to know is this

    is there a way that i can have a image displayed and on a click of a command button a timer start from 1 - 96 and durining that timer event have my image move from the top of the imagebox to the bottom but the thing is i need the image to display the bottom part of the image to then show the whole of the image then at the bottom just show the top of the image

    basically to make it look like the image is scrolling down. a bit like a reel on a fruit machine

    any help would be nice.

  2. #2
    Join Date
    Dec 2008
    Posts
    19

    Re: how to move images in a imagebox

    One of the ways to accomplish this is to put your image box inside a picture box container. Then through a timer event use the Image1.Move Left, Top syntax. The left would stay the same but the the Top property would change within a loop (for/next) where when starting the Top would be a negative number. It would increment in the loop until the Top positioned the image outside the bottom paramater of the picture box container (which would be a positive number greater than the height of the image).

  3. #3
    Join Date
    Dec 2008
    Posts
    24

    Re: how to move images in a imagebox

    thanks for your reply but somehow managed to get what i wanted using a imageox inside a frame then using a timer function and the imagebox.top method then hard coding from the timer sequence so that after 10 miliseconds 100 was added to the imagebox.top value.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: how to move images in a imagebox

    Try this:

    It scrolls a pixel at a time. Can't get any smoother. Notice that there are TWO Label Controls

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    'set up text display
        Label1(0).AutoSize = True
        Load Label1(1)
        Label1(1).Visible = True
        Picture1.Height = Label1(0).Height + 60
        Picture1.ScaleMode = vbPixels
    End Sub
    
    Private Sub Command1_Click()
     'text we want to display
     SetText "Hello World! - from DAVID, MVP - Visual Developer"
     'set scroll speed
     Timer1.Interval = 20
    End Sub
    
    Private Sub Timer1_Timer()
        ScrollText
    End Sub
    
    'use this routine to set the display text
    Sub SetText(StrText As String)
        Label1(0) = StrText & Space(10)
        Label1(1) = Label1(0)
        Label1(0).Left = 0
        Label1(1).Left = Label1(0).Width
    End Sub
    
    'Here is where we do all the work
    Public Sub ScrollText()
     Static i As Integer
     Dim k As Integer
     k = i Xor 1 'other label
     'move the label left by one pixel
     Label1(i).Left = Label1(i).Left - 1
     'other label follows like a train
     Label1(k).Left = Label1(i).Left + Label1(i).Width
     'if engine is off screen, then make it caboose
     If Label1(k).Left = 0 Then i = k
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: how to move images in a imagebox

    Quote Originally Posted by d0uga1 View Post
    thanks for your reply but somehow managed to get what i wanted using a imageox inside a frame then using a timer function and the imagebox.top method then hard coding from the timer sequence so that after 10 miliseconds 100 was added to the imagebox.top value.
    Hard coding a animation sequence is not always the best way to do it ..
    I have a lot of reading for you to do...

    Animation Part 1 - Basics
    Animation Part 2 - Bitmaps

    Moving images with key press
    Crop And Zoom images

    It's a lot of reading, but the projects and code snips in these articles and threads will give you just about everything you need to know about animating images..

    Gremmy..
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

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

Featured