VB.net最近控件
有没有一种简单的方法可以让控件距离所选控件最近?
我有一个图片框和一些其他移动控件。我想删除距离我的图片框最近的控件。
因此,我必须获取所有控件的位置,并删除位置最接近图片框位置的控件。我不确定如何最好地做到这一点。
Is there an easy way to get the nearest control to a control of choice?
I have a picture box and some other moving controls. I want to delete the nearest control to my picture box.
So I have to get the position of all controls and delete that with the Location nearest to the Location of my picture box. I'm not sure about how to do that the best way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的情况中的“最接近”确实意味着“位置最接近我的图片框的位置”,那么最简单的是:
,其中 Distance 在如下模块中定义:
If "closest" in your case indeed means "with the Location nearest to the Location of my picture box", then the easiest would be:
, where Distance is defined in a module like this:
这是一个完整的示例表单,通过检查提供的控件是否位于相对于基本控件的 8 个区域之一来计算“最接近”。一半的代码是为了模仿您描述的场景而设置的。
MainButton_Click
及其下面是工作的重点。Here's an entire sample form that calculates "closest" by checking if the supplied control is in 1 of 8 regions relative to the base control. Half of the code is setup trying to mimic the scenario you described. The
MainButton_Click
and below is the meat of the work.