Click to See Complete Forum and Search --> : moving shapes
opus
Aug 23rd, 2000, 03:18 PM
hi, I'm trying to move standard VB-Shapes and -Lines together. For example a circle with a line that starts in the middle of the circle. If I start moving these along the picture box the line seems to be "wobbeling" in the circle, instead of beeing fixed to the centre.
I'm using a "user-Scale" in the picturebox to determine the positions.
What's wrong?
Mad Compie
Aug 24th, 2000, 01:18 PM
I don't know.
Please send the code.
How do you move a VB Shape Control anyway?
Fox
Aug 24th, 2000, 01:28 PM
Use the .move method of the shape
Shape1.move x, y, [w, h]
Where x and y are the coordinanates and w and h (optionally) are the size.
Mad Compie
Aug 24th, 2000, 01:46 PM
Sure about that, but I meant how do you know when you move the cursor over the shape? Or is this shape at a fixed position and not important...
opus
Aug 24th, 2000, 03:00 PM
I give you an example of the problem. Use the following code in a timer, to move a circle(shape1) and a line (line1) on a form. Use Scalemode User; ScaleHeight -10 ScaleWidth 10 ScaleTop 5 ScaleLeft -5 on the Form. You will find that the line is "wobbeling" in the circle
[code:]
Private Sub Timer1_Timer()
Shape1.Move Shape1.Left + 0.02, Shape1.Top - 0.01
Line1.X1 = Shape1.Left + Shape1.Width / 2
Line1.X2 = Shape1.Left
Line1.Y1 = Shape1.Top - Shape1.Height / 2
Line1.Y2 = Shape1.Top
End Sub
[/code:]
BillSoo
Aug 24th, 2000, 05:59 PM
It's a rounding error kind of thing. You can't exactly get the center of the circle so the line goes to one pixel or another off center.
If you move the circle an even number of pixels at a time, then the center can be calculated exactly. However, your coordinate system doesn't lend itself to pixels easily.
As an alternative, try scalemode=pixels, shape1.width=shape1.height=40 (or some other even number)
Private Sub Timer1_Timer()
Shape1.Move Shape1.Left + 2, Shape1.Top - 2
Line1.X1 = Shape1.Left + Shape1.Width / 2
Line1.X2 = Shape1.Left
Line1.Y1 = Shape1.Top + Shape1.Height / 2
Line1.Y2 = Shape1.Top
End Sub
Or if you are committed to a user defined scalemode, make a increment that is an exact even multiple of pixels.
for instance:
Dim incX as double
Dim incY as double
Private Sub Form_Load()
Me.ScaleMode = 3 'pixels
incX = 2 * 10/Me.ScaleWidth
incY = 2 * 10/Me.ScaleHeight
Me.ScaleMode = 0
Me.ScaleWidth=10
Me.ScaleHeight = -10
Me.Left = -5
Me.Top = 5
End Sub
Private Sub Timer1_Timer()
Shape1.Move Shape1.Left + incX, Shape1.Top - incY
Line1.X1 = Shape1.Left + Shape1.Width / 2
Line1.X2 = Shape1.Left
Line1.Y1 = Shape1.Top - Shape1.Height / 2
Line1.Y2 = Shape1.Top
End Sub
opus
Aug 25th, 2000, 02:20 AM
Thank's for the help, but your solution is not working for me, 'cause I can't set the increments to anything, they are determined by the system( it's the movement of Ships using differnt course and speed).
I think I have to work a way to use the Pixel-Mode, but that a LOONG way. Thank's anyway
Mad Compie
Aug 25th, 2000, 01:51 PM
Perhaps with a For...Next loop combined with DoEvents you can prevent the flicker and speed the movement up
Illuminator
Aug 25th, 2000, 02:31 PM
why dont you just make a simple control which contains all of the shapes you will be moving. Then all you have to do is move the control and the internal shapes maintain their relative postitions.
opus
Aug 25th, 2000, 03:46 PM
Maybe I'm stupid, but what do you mean with that "simple control", and whow would you do that?
Illuminator
Aug 25th, 2000, 05:29 PM
Add a "user control" to you app and use the line and circle controls to draw the appropriate shapes on the user control.
Set the background property of the user control to transparent.
Close the design window and open the main form. You control should now be present in the toolbox.
Put this on the form where you would normally place the shapes.
To move the control around at runtime just set the top and left properties like you would with any other control.
(when i said simple i meant that this process of adding the control would be easy)
~Hope this works I haven't tested it.
Arcom
Aug 28th, 2000, 07:19 PM
I will have to dissapoint Illuminator (and maybe opus too), but setting UserControls' BackStyle to transparent will HIDE EVERYTHING there is on that control. Believe me, I tried it.
If you go this way, you must draw shapes on the usercontrol, then set the Image to MaskPicture (MaskPicture = Image)
Or if you don't want to use (don't need) transparent backgrounds simply leave the BackStyle setting to Opaque.
As simple as it gets :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.