Results 1 to 5 of 5

Thread: [RESOLVED] If in Panels bounds?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Resolved [RESOLVED] If in Panels bounds?

    Hello

    I have an application where I have different picture boxes which the user can drag and move.
    I also have different empty pictureboxes.

    What I want to do:
    I want to let the user be able to drag a picturebox to one of the empty pictureboxes. Also, If the user drags a picturebox to an invalid place (outside the bounds of any of the empty pictureboxes), the dragged picture box should return to its previous location.

    So what I currently have is the usual drag-drop code and on the MouseUp event, I run this code (currently only checking for one empty picturebox):
    Code:
                If Not pbEmpty1.Bounds.Contains(Me.PointToClient(pbRemote.Location)) Then
                    pbRemote.Location = OldLocation
                End If
    (pbEmpty1 = Empty picturebox, pbRemote = picturebox that is dragged)

    But it doesn't work, it doesn't care if the picturebox is inside the bounds of the empty picturebox or not, it still returns to its previous location...

    Any help please?
    Thanks, Zeelia

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: If in Panels bounds?

    try this:

    vb Code:
    1. If Not pbEmpty1.Bounds.intersectswith(pbRemote.bounds) Then
    2.     pbRemote.Location = OldLocation
    3. End If

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: If in Panels bounds?

    Thank you, paul!
    I've been trying to do this for quite some time now and the solution was just as easy as this, if I only had looked through the methods of 'Bounds'.

    Just one more question, is the (empty) picturebox a good object to use in my case? (I just want to check if the picturebox enters the bounds)
    Maybe a panel would be appropriate aswell, what do you think?

    Thanks!
    //Zeelia
    Last edited by Zeelia; Mar 17th, 2010 at 03:16 PM.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: If in Panels bounds?

    it depends what you're trying to do. panels are recommended as containers + pictureboxes aren't intended for that purpose.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    519

    Re: If in Panels bounds?

    Yeah, that's just my thought, Paul.

    That's why I got a bit.. curious about why I chose pictureboxes as the boundary containers...
    Ah well, It does work pretty good anyways

    Thanks for the help ^.^
    //Zeelia

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