可拖动的用户控件不会拖动! [英] Dragable User Control does not drag!

查看:83
本文介绍了可拖动的用户控件不会拖动!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在用户控件库中创建了一个用户控件.我为拖放添加了功能,在构造函数中,我将控件分配给了使用的事件处理程序.
当我需要一个新的用户控件,并将其添加到VS中时,然后进行拖动即可正常工作.但是,当我在运行时创建用户控件时,拖动不再起作用了吗?在运行时,我使用
创建用户控件

Hi,
i created a User Control in am User Control Library. I added funktionallity for drag and drop, in the Constructor i assign the Control to the used Event handlers.
When i need a new User Control, and i add it in VS, then dragging works fine. But when i create a User control during runtime, dragging does not work any more? During Runtime i create the user Control with the

myLibrary.myUserControl myControl = new myLibrary.myUserContro(); 



http://msdn.microsoft.com/en-us/library/cc189066 (v = vs.95).aspx [



http://msdn.microsoft.com/en-us/library/cc189066(v=vs.95).aspx[^]

My Logic for moving around the User Control looks like this. Works if the User Control is added via VS, but not if added during Runtime.

Any Ideas?

greets

推荐答案

该问题的解决方案很简单,但并不直观.若要将拖放事件传递给UserControl中的子控件,请在UserControl项目中将UserControl的AllowDrop属性设置为false.然后将其子控件的AllowDrop属性设置为true.完成这些更改后,UserControl将不会拦截旨在用于其子控件的拖放事件.

请注意,在客户端窗体中更改UserControl的AllowDrop属性无效.将UserControl添加到窗体后,无论UserControl的AllowDrop属性设置为true还是false,其子控件都将接收拖放事件.
The solution to this problem is simple, but it isn''t intuitive. To pass drag-and-drop events to child controls in a UserControl, set the AllowDrop property of the UserControl to false in the UserControl project. Then set the AllowDrop properties of its child controls to true. Once these changes are made, the UserControl won''t intercept drag-and-drop events intended for its child controls.

Note that changing the UserControl''s AllowDrop property in a client form has no effect. When the UserControl is added to a form, its child controls will receive drag-and-drop events regardless of whether the UserControl''s AllowDrop property is set to true or false.


这篇关于可拖动的用户控件不会拖动!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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