'Detect an object when it's getting closer to another

What I have are: a picturebox, a few walls.

the picturebox can move, and as moving freely around it eventually collides to walls.

What I want to do is detecting walls before the pictureBox1 actually collides/touches to them, so that the picturebox can change direction and keep moving.

What I tried:

  1. Bounds.IntersectsWith() > the picturebox must not touch walls, it must not intersect with them.
  2. Location(Bounds).X + 10 (Tried so to make an unvisible radar) sort of thing, but as an object's location is fixed to top left, it didn't work.

And I no longer have ideas... Any help would be highly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source