Overlapping controls

C

Charlie Brown

I have a form with 2 custom controls that can be dragged around by a
user. How can I check if they overlap each other without performing
some kind of Collision detection on them? Is there anything in GDI to
check for overlapping controls?
 
S

Steve Long

Yes, it's called math.
If one of the controls' left property is < another controls' left property +
it's width property, guess what, the former is overlapping the latter (in
checking for the x location only). Do the math for the rest.

HTH
Steve
 
C

Charlie Brown

Thank you for your sarcastic reply Steve. Some of my controls are not
rectangles, so checking for overlaps using math becomes a bit more
complex than simple addition. I was looking to see if there was
something built into the framework that already did the check, for
example, checking z order on overlapping controls or something similar.
I have done collision detection classes before, but looking for an
existing solution before beginning is usually the more productive way
to code software.

In the future when you reply to someone, curb the sarcasm, and put some
thought into your answer. Although I didn't mention whether I was
testing for rectangles or not, you could have asked.
 
C

Cor Ligthert [MVP]

Charlie,

Overlapping controls is allowed, so it would be strange if there was a check
for that.

It is often used to hide controls or even more by using the splitter.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top