Results 1 to 7 of 7

Thread: Moving 'shape' controls with mouse

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Cardiff, UK
    Posts
    6

    Talking Moving 'shape' controls with mouse

    Does anyone know any quick way of being able to move 'shape' (rectangle) controls around a picture box using a mouse.

    As far as I know 'shape' controls don't allow DragNDrop mode.

    Any help would be grateful, cheers.

  2. #2
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Play around with MouseMove and MouseDown/MouseUp
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  3. #3
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    hm I think that's a pretty sucky thing to do because I think you are right that they do not have a drag and drop and I think they have no events either...
    if not that's not going to be fun
    you would need to check if a mouseclick is about the control and than move it with the mouse until you register a mouse up...
    there could be some pretty funky things happening if you try to do this without api
    Sanity is a full time job

    Puh das war harter Stoff!

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Cardiff, UK
    Posts
    6
    No you're right the 'shape' control doesn't have any associated events, and it is going to be a bugger!
    Aaaarrgggh, anybody got any reason why VB doesn't have an event for this control - it seems daft!

  5. #5
    PowerPoster Arbiter's Avatar
    Join Date
    Sep 2000
    Location
    Manchester
    Posts
    2,276
    It's not really a control, it's just there to 'pretty' up your app.

    You could trap the events on the form the shapes are on and compare the co-ordinates of the mouse to the shapes position...?
    Gentile or Jew,
    O you who turn the wheel and look to windward,
    Consider Phlebas, who was once handsome and tall as you...

  6. #6
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    that's what I meant and that also is a pain in the ... .
    Especially if there is overlapping..
    hm maybe you just want to use a picturebox and blit some kind of backbuffer with colors corresponding to each object, so you could use getpixel and look up which object that is...
    Sanity is a full time job

    Puh das war harter Stoff!

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2002
    Location
    Cardiff, UK
    Posts
    6
    A HAVE IT ALL UNDER CONTROL
    The solution is below:

    Must have the following controls on the form

    PictureBox - PictureBox1 (Autoredraw=true, scalemode=pixels)
    Shape - Shape1

    Place shape1 anywhere inside the picturebox, and use:



    Dim moveTriggered As Boolean
    Dim shapeX As Integer
    Dim shapeY As Integer
    Dim shapeWidth As Integer
    Dim shapeHeight As Integer
    Dim xOffset As Integer
    Dim yOffset As Integer

    Private Sub Form_Load()
    moveTriggered = False
    shapeX = Shape1.Left
    shapeY = Shape1.Top
    shapeWidth = Shape1.Width
    shapeHeight = Shape1.Height
    End Sub

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Select Case moveTriggered
    Case True
    If Button <> 1 Then
    shapeX = Shape1.Left
    shapeY = Shape1.Top
    moveTriggered = False
    Else
    Shape1.Move (X - xOffset) + shapeX, Y - (yOffset - shapeY)
    End If
    Case False
    If Button = 1 And X > shapeX And Y > shapeY Then
    If X < shapeX + shapeWidth And Y < shapeY + shapeHeight Then
    xOffset = X
    yOffset = Y
    moveTriggered = True
    End If
    End If
    End Select

    End Sub





    It works a beauty. And you can release it, and keep moving it too, just what I wanted. Let me know if it works.

    Cheers guys!

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