移动控件时,将控件置于下方 [英] While moving a control get the control underneath
问题描述
大家好,
我拥有一个控制权(打牌),无法在面板上自由移动.
移动此卡时,我需要知道是否还有另一个控件以及面板上的哪个控件.
我无法使用mouseenter或muosehover,因为按下鼠标按钮时此事件不起作用.
谢谢你的帮助
克里斯蒂安
hi all,
I''ve a control (a card play )than I can move freely on a panel.
While moving this card I need to know if there is another control and which control is underneath on panel.
I can''t use mouseenter or muosehover ''cause this events doesn''t work while pressing a mouse button.
thank you for help
christian
推荐答案
如果您拥有扁平的控件结构,则始终可以使用控件的Parent.Controls
来获取所有对等项.使用该控件集合,您可以获取与之相交或包含以下内容的所有控件:
If you have a flat structure of controls, you can always yous your control''sParent.Controls
to get all peers. With that collection of controls you can get all controls your control intersects with or contain:
Control myMovingControl = //...
Rectangle currentSite = my myMovingControl.Bounds;
foreach(Control peer in myMovingControl.Parent.Controls) {
Rectangle peerSite = peer.Bounds;
if (currentSite.Contains(peerSite)) {
//do something about the case when your moving control
//completely covers the peer control.
}
if (currentSite.IntersectsWith(peerSite)) {
//do something about the case when your moving control
//partially covers the peer control.
}
}
如果您不仅要检查其他控件,还需要对等控件,则需要收集您喜欢的任何集合(例如System.Collections.Generic.List<Control>
)中所有有问题的控件,并以相同的方式在foreach
语句中使用此集合. />
还有其他问题吗?
您的问题就解决了.
If you have to check up some other controls not only peers, you need to collect all the controls in question in any collection you prefer (such as System.Collections.Generic.List<Control>
) and use this collection in the foreach
statement the same way.
Any further questions?
You problems is solved.
这篇关于移动控件时,将控件置于下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!