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...
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!
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.
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!
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.
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.
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.
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!
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:
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..)
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.