Reputation: 373
I have a small popup window , and I'd like to trigger event when I click the mouse outside of the window bound.
I've tried initiating it on OnMouseClick, and check if the mouse cursor is out of the pop up bounds, but it doesn't seem to trigger out of the popup bounds.
Upvotes: 2
Views: 627
Reputation: 4862
For discussion:
public partial class FrmPopup : Form {
public FrmPopup() {
InitializeComponent();
}
const uint WM_NCACTIVATE = 0x0086;
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
if (m.Msg == WM_NCACTIVATE && m.WParam == IntPtr.Zero) {
if(!ClientRectangle.Contains(PointToClient(Control.MousePosition)) && MouseButtons == MouseButtons.Left)
label1.Text = "Clicked outside of window";
}
}
}
Upvotes: 2
Reputation: 271
Have you considered the Deactivate event? This will fire when the form loses focus. This could be from a mouse click OR a context switch, but may deliver what you want.
Upvotes: 1