Results 1 to 12 of 12

Thread: moving shapes

  1. #1

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Angry

    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?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  2. #2
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Question

    I don't know.
    Please send the code.
    How do you move a VB Shape Control anyway?

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Use the .move method of the shape

    Code:
    Shape1.move x, y, [w, h]
    Where x and y are the coordinanates and w and h (optionally) are the size.

  4. #4
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Cool

    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...

  5. #5

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    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:]
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6
    New Member
    Join Date
    Aug 2000
    Location
    Vancouver BC
    Posts
    4
    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
    "I have a plan so cunning you could pin a tail on it and call it a weasel!" - Edmund Blackadder

  7. #7

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    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
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Perhaps with a For...Next loop combined with DoEvents you can prevent the flicker and speed the movement up

  9. #9
    Lively Member
    Join Date
    May 2000
    Posts
    84
    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.

  10. #10

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Maybe I'm stupid, but what do you mean with that "simple control", and whow would you do that?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  11. #11
    Lively Member
    Join Date
    May 2000
    Posts
    84
    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.

  12. #12
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200

    Thumbs down

    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

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