Reputation: 24695
I have a custom UserControl. I want to use it in a few different products, so I want something that can be implemented inside of the UserControl itself. I want to know when the user has clicked outside of the bounds of the UserControl so that I can hide it, similar to a ComboBox. How can I do that?
I tried handling the click event, but it only seems to fire if the click occured within the bounds of the control.
Upvotes: 3
Views: 1505
Reputation: 942548
That's what the Capture property is designed to do. Set it to true and all mouse messages are routed to your control, even if it moves out of the window bounds. Check the e.Location property in the MouseDown event.
Upvotes: 3
Reputation: 15354
do this
Code:
if (!sender.Equals(yourControl))
{
yourControl.Visible=false;
}
Upvotes: -1
Reputation: 1169
Hm, you may be able to accomplish what you want by listening to the GotFocus/LostFocus events. ComboBoxes give the drop downs focus when they open and close them when they lose focus.
Upvotes: 1