Parent Control Mouse Enter/Leave Events With Child Controls

前端 未结 5 1033
天涯浪人
天涯浪人 2020-11-27 18:49

I have a C# .NET 2.0 WinForms app. My app has a control that is a container for two child controls: a label, and some kind of edit control. You can think of it like this,

5条回答
  •  有刺的猬
    2020-11-27 19:16

    i don't think you need to hook the message pump to solve this. Some flagging in your UI should do the trick. i'm thinking that you create a member variable, something like Control _someParent, in your controlling class which will take the reference of the parent control when one of your OnMouseEnter handlers is called. Then, in OnMouseLeave, check the value of the _someParent "flag" and if it's the same as the current sender's then do not actually stop your processing, just return. Only when the parent is different do you stop and reset _someParent to null.

提交回复
热议问题