动态生成的控件问题
我有一个带有停靠在其中的面板的表单。然后,我在主面板(名为 ContainerPanel)上动态创建 15 个面板(名为:panel_n)和 15 个图片框(名为:picturebox_n)。
将任何图片框拖动到使用相关鼠标事件创建的面板 (panel_n) 上时。我想获取图片框被拖过的面板的名称。鼠标光标似乎被捕获。
我尝试创建一个 IMessageFilter 界面,但将其中一个图片框拖动到任何一个面板上时仍然没有触发任何事件。
ClientRectangle.IntersectsWith 函数也不起作用,因为坐标始终为 0,0。
我需要的只是图片框被拖过的面板名称(最好是在 mouseup 事件上)
I have a form with a panel docked in it. I then dynamically create 15 panels (named: panel_n) and 15 pictureboxes (named: picturebox_n) on the primary panel (named ContainerPanel).
When dragging the any picturebox over a panel (panel_n) created using the relevant mouse events. I would like to get the panel's name that the picture box was dragged over. The mouse cursor seems to be captured.
I have tried creating a IMessageFilter interface, but there are still no events that trigger when dragging one of the pictureboxes over any one of the panels.
The ClientRectangle.IntersectsWith function also does not work as the co-ords are always 0,0.
All I need is the panel name where the picturebox was dragged over (preferably on the mouseup event)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您为图片框提供一个 OnMouseDown 事件,其内容如下:
然后您可以将面板的 AllowDrop 属性设置为 true,并在其 OnDragDrop 事件中,您可以获取其名称,如下所示:
编辑: 另外,您需要为面板提供如下所示的 OnDragEnter 事件:
当然,您可以将
Copy
更改为Move
或Link
或任何适合的内容你在做什么。它只是更改所使用的鼠标指针图标。If you give the pictureboxes an OnMouseDown event that says something like this:
Then you can set the panels' AllowDrop property to true, and in their OnDragDrop event, you can get their name like this:
Edit: Also, you need to give the panels an OnDragEnter event like this:
Of course, you can change
Copy
toMove
orLink
or whatever is appropriate for what you're doing. It just changes the mouse-pointer icon that's used.