【发布时间】:2012-09-21 04:22:08
【问题描述】:
我有一个用户控件
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;
}
}
当我漂浮在包含在父窗体中的用户控件上时,断点不会被命中。断点在附近被击中,但我可以在用户控件内的实际文本框中而不被击中。如何准确确定我是否在此用户控件的范围内?
FWIW,我有两台显示器。我使用的显示器似乎没有什么区别。
【问题讨论】:
-
@DanielA.White 我在您的链接中看到的答案是针对单个控件的。请注意,我在这里连接到一个全局消息过滤器。我认为那些行不通。最终我需要确切地知道鼠标在哪个控件上,而不仅仅是包含子控件的一般用户控件。