如何检测图片框在一行上的拖放? [英] How to detect picturebox drag drop on a line?
本文介绍了如何检测图片框在一行上的拖放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我画了一条线,想检测是否在其上放置了任何图片框.
I have a line drawn and want to detect if any picturebox is being placed on it.
推荐答案
如果我错了,有人可以纠正我,但是我想这会变得很复杂.
首先,我假设您正在Visual Basic PowerPack中使用LineShape
? (是的,我知道这是C#吗?)
即使您不是以编程方式在窗体上画一条线,您也将不得不使用窗体的拖动事件或绘制该窗体的容器.
假设您已经拖动了PictureBox
,请首先钩住Form的DragEnter
和DragOver
事件,然后在该代码中,首先检查是否存在PictureBox
.
Someone can correct me if I''m wrong, but it''s going to be complicated, I think.
First, I assume you''re using theLineShape
from within the Visual Basic PowerPacks? (and yes, I know this is a C# ?)
Even if you''re not and just drawing a line on the form programmatically, you''re going to have to use either the form''s drag events, or the container that it is drawn on.
Assuming you already have aPictureBox
being dragged, first hook the Form''sDragEnter
andDragOver
events and in that code, first, check if there is aPictureBox
present
if (e.Data.GetDataPresent(typeof(PictureBox))
那么您必须检查它是否在线路上.如果它是VB PowerPack中的LineShape
,则可以执行HitTest
then you have to check if it''s over the line. If it''s a LineShape
from the VB PowerPacks, you can do a HitTest
if (lineShape1.HitTest(e.x,e.y))
然后,将e.Effect
设置为想要的效果.然后,您在表单中处理DragDrop
并将PictureBox
添加到DragDrop
发生的那一行.
Then, you set e.Effect
to what effect you want. Then, you handle the DragDrop
in the form and add the PictureBox
to the line that the DragDrop
happened over.
要添加到其他答案中,如果您''如果要重新做这么复杂的事情,如果抛开图片框并在绘画事件中绘制图片,它将变得更加容易(但仍然很复杂).这样可以使您对发生的事情有更多的控制.
To add to the other answer, if you''re going to do something this complex, it becomes a lot easier ( but still complex ) if you ditch the picturebox and just draw the picture in your paint event. This gives you a lot more control over what is going on.
如何进行线路测试?您能给我一些代码吗?
How can i do a line test? Could you provide me with some codes?
这篇关于如何检测图片框在一行上的拖放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文