CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2005
    Posts
    67

    Making a scroll screen

    Well, what i basicly want to make is a screen the moves when you reach a border with the mouse. For example, if i reach the upper edge of the form with my mouse, I want what you see in the form to go upwards...can you think of a strategy game? Warcraft for example? in which you can scroll your screen with your mouse... can anyone help me please?
    thnx...

  2. #2
    Join Date
    Sep 2005
    Location
    Delhi, INDIA
    Posts
    237

    Re: Making a scroll screen

    Hi Limpit,

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If X < Frame1.Left Then
            Frame1.Left = X
        End If
        
        If X > (Frame1.Left + Frame1.Width) Then
            Frame1.Left = X - Frame1.Width
        End If
        
        
        If Y < Frame1.Top Then
            Frame1.Top = Y
        End If
    
    
        If Y > (Frame1.Top + Frame1.Height) Then
            Frame1.Top = Y - Frame1.Height
        End If
        
        
    End Sub
    try this in a Form with a Frame !

    Is this you want or something like that?
    I'M BACK AGAIN !!
    -------------------------------------------------------------------------
    enjoy the VB !
    If any post helps you, please rate that.
    Always try to findout the Solutions, instead just discussing the problem and its scope!

  3. #3
    Join Date
    Sep 2005
    Posts
    67

    Re: Making a scroll screen

    Yea sure...but how do i make the frame?

  4. #4
    Join Date
    Mar 2005
    Location
    Nottingham, UK
    Posts
    665

    Re: Making a scroll screen

    Frames are just one of the standard controls that you can drop onto your form. The Frame Control icon is located directly beneath the Textbox icon.

    Frames are just containers - you can place controls inside them and if you move the frame, all the controls inside will move as well. Very useful things.

    ...

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Making a scroll screen

    Yes, Dan is right.
    Just an important thing about using Frames:
    Seeing the fact that Frames are container objects, the controls you want inside the Frames, you need to draw them manually inside the Frames. Just click the control once then click and drag it inside the frames.
    If you were to just double click on a control, then move it inside the frame, it's not going to work, because the Form is also a Container object and every control double clicked in the toolbox, will be contained on the form.
    You could also just Cut the control you want in the frame, then select the frame, then paste it in there!

  6. #6
    Join Date
    Mar 2005
    Location
    Nottingham, UK
    Posts
    665

    Re: Making a scroll screen

    Also, Rahul's code will move the frame around the form. If you want to create a scrolling effect, one method is the old dual picturebox technique.

    Place a picturebox on a form, and then place a second picturebox inside the first. The inner picturebox can be any size you want - preferably much bigger than the outer picturebox. You can place controls or a picture in the second picturebox, then use the following code
    Code:
    Option Explicit
    Private startX As Long, startY As Long
    
    Private Sub Form_Load()
        Me.ScaleMode = vbPixels
        
        With picOuter
            .ScaleMode = vbPixels
            .AutoRedraw = True
            .AutoSize = False
        End With
        
        With picInner
            .ScaleMode = vbPixels
            .AutoRedraw = True
            .AutoSize = True
            .BorderStyle = 0
            .Move 0, 0
        End With
        'Change the picture path to load your own picture here
        picInner.Picture = LoadPicture("C:\Documents and Settings\Dan\My Documents\My Pictures\splash7.jpg")
        
    End Sub
    
    Private Sub picInner_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        startX = X
        startY = Y
    End Sub
    
    Private Sub picInner_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Button = 1 Then
            If startX > X Then picInner.Left = picInner.Left - 1
            If startX < X Then picInner.Left = picInner.Left + 1
            If startY > Y Then picInner.Top = picInner.Top - 1
            If startY < Y Then picInner.Top = picInner.Top + 1
        End If
    End Sub
    When you click and drag, the inner picturebox will move around inside the outer one, creating a scrolling impression.

    ...
    Last edited by Dan_H; November 24th, 2005 at 09:24 AM.

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

    Re: Making a scroll screen

    Heres a little project i dumped a long while ago but it has exactly what your looking for..

    Run it and dbl click on the text box at the top to Open a file.. Choose a relatively large image..
    Left click on the image to move the image around.. move over the borders of the image to see the scrolling..

    the code used is very simple..

    SomeThing to note.. 'MouseMove' is only trigered when the mouse moves over the respective area.. if the mouse comes to a stop 'MouseMove' is called only once..

    In this code a small 'Bug' (If we can call it that), Rather a Quirk is that the method i used for scrolling causes the 'MouseMove' event to be retrigerd.. give a nice smooth scroll..

    Gremmy
    Last edited by GremlinSA; November 26th, 2005 at 06:33 AM.
    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.

  8. #8
    Join Date
    Mar 2005
    Location
    Nottingham, UK
    Posts
    665

    Re: Making a scroll screen

    Your project works quite nicely Gremlin, apart from the scroll bars, which are a bit buggy.

    I have a version of the code I posted above that purely uses scroll bars to scroll the image - its more substantial than what I posted above, but also works beautifully.

    ...
    Last edited by Dan_H; November 24th, 2005 at 07:37 PM.

  9. #9
    Join Date
    Sep 2005
    Location
    Delhi, INDIA
    Posts
    237

    Re: Making a scroll screen

    I Agreed with Dan_H Also..

    The Method is also a Beautiful way to scroll. !
    I'M BACK AGAIN !!
    -------------------------------------------------------------------------
    enjoy the VB !
    If any post helps you, please rate that.
    Always try to findout the Solutions, instead just discussing the problem and its scope!

  10. #10
    Join Date
    Sep 2005
    Posts
    67

    Re: Making a scroll screen

    wow thnx for the help guys...nice code gremlin...well I didnt exactly want the scroll bars for I used command buttons to scroll the screen... I just dont know how to make borders for the picture...look at my project:
    Attached Files Attached Files

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

    Re: Making a scroll screen

    Quote Originally Posted by limpit
    wow thnx for the help guys...nice code gremlin...well I didnt exactly want the scroll bars for I used command buttons to scroll the screen... I just dont know how to make borders for the picture...look at my project:
    The code you used isnt too bad but has a small Flaw.. if you move over the command on the left -move up to the top command then over to the right one.. you have 3 timers running.. doing: X + 100, Y + 100 and X - 100.. the image now makes a funny movement..
    Code:
    \
    /
    \
    /
    \
    /
    I've reposted my code with out scrollers (Just hid them actaully..)

    Try it now..

    Gremmy
    Attached Files Attached Files
    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