You could do this in a lostfocus event on the popup or in the gotfocus event of the calling window.
I would try to code it in the gotfocus of the calling window myself but that can cause issues if you need to validate something on the popup before it closes.
Instead of making it a seperate window you could make it a user control that you hide and show instead.
I will see if I can figure out your problem though.
When you show your popup user control, set its "Capture" property to true.
Look at Mouse events. If you get a mouse-down event that is outside your control's client area, set "Capture" to false and hide your control.