Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Controls Overlapping

Controls Overlapping

Scheduled Pinned Locked Moved C#
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silvyster
    wrote on last edited by
    #1

    I'm creating a lot a picture boxes. Each picture box has a constant height and width of 50. So I randomly place this picture boxes on the form. My problem is that some picture boxes overlaps or on top of other picture box. How do I solve this problem?

    C 1 Reply Last reply
    0
    • S Silvyster

      I'm creating a lot a picture boxes. Each picture box has a constant height and width of 50. So I randomly place this picture boxes on the form. My problem is that some picture boxes overlaps or on top of other picture box. How do I solve this problem?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You need to look at the existing picture boxes and if they overlap with your new picture box then move your new picture box. Detecting an overlap is fairly simple. Each control can give you its Bounds[^], which is a Rectangle[^] object. The Rectangle structure has an IntersectsWith[^] method which will return true if the rectangles intersect (overlap) with each other. For example:

      bool isOverlapping = firstPictureBox.Bounds.IntersectsWith(secondPictureBox.Bounds);

      Developer Day Scotland 2 - Free community conference Recent blog posts: *Throwing Exceptions *Training Developers * Method hiding or overriding - or the difference between new and virtual

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups