移动控件时,将控件置于下方 [英] While moving a control get the control underneath

查看:74
本文介绍了移动控件时,将控件置于下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我拥有一个控制权(打牌),无法在面板上自由移动.
移动此卡时,我需要知道是否还有另一个控件以及面板上的哪个控件.

我无法使用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''s Parent.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语句中使用此集合. />
还有其他问题吗?
您的问题就解决了.

—SA



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.

—SA


这篇关于移动控件时,将控件置于下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆