I have a user control
public partial class UserControl1 : UserControl, IMessageFilter { public UserControl1() { InitializeComponent(); Application.AddMessageFilter(this); } public bool PreFilterMessage(ref Message m) { var mouseLocation = Cursor.Position; if (Bounds.Contains(PointToClient(mouseLocation))) { bool aBool = true;//breakpoint bool two = aBool;//just assignment so compiler doesn't optimize my bool out } if (m.Msg != 0x20a) // Scrolling Message { return false;//ignore message } return false; } }
When I float over the user control contained in a parent form, the breakpoint is not hit. The breakpoint is hit in close proximity, but I can be in an actual textbox inside the user control and not get a hit. How can I accurately determine if I am within the bounds of this user control?
FWIW, I have two monitors. It does not appear to make a difference which monitor I am using.
Try your hit testing against Control.ClientRectangle
rather than Control.Bounds
:
if (ClientRectangle.Contains(PointToClient(Control.MousePosition))) { bool aBool = true;//breakpoint bool two = aBool; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With