拖拽多选控件我在WinForms窗体上有一个动态创建多个实例的UserControl。如果我选择它,我可以拖动它。现在,我认为,如果我选择多个UserControl(使用ctrl+按钮单击),我可以同时拖动它们。我可以像对UserControl那样做吗?到目前为止我已经尝试过的事情://对于拖动我使用了这个方法并且我也从.netpublicvoidStartDrag(){dragging=true;覆盖了MouseUp,MouseDown,MouseMove点p=PointToClient(Cursor.Position);dragStart=newPoint(Math.Max(0,pX),Math.Max(0,pY));buttondrag.Capture=true;}privatevoidUsercontrol1_SelectedChanged(objectsender,EventArgse){if(((UserControl)sender).Selected){if(SelectedUserControl.Count>1){foreach(UserControlcinpanel1.Controls){c.StartDrag();}}}}//将控件放在面板中,然后使用这个类。类ControlMover{publicenumDirection{Any,Horizo??ntal,Vertical}publicstaticvoidInit(Controlcontrol){Init(control,Direction.Any);}publicstaticvoidInit(Controlcontrol,Directiondirection){Init(control,control,direction);}publicstaticvoidInit(Controlcontrol,Controlcontainer,Directiondirection){boolDragging=false;PointDragStart=Point.Empty;control.MouseDown+=delegate(objectsender,MouseEventArgse){Dragging=true;DragStart=newPoint(eX,eY);控制.Capture=true;};control.MouseUp+=delegate(objectsender,MouseEventArgse){Dragging=false;控制.Capture=false;};control.MouseMove+=delegate(objectsender,MouseEventArgse){if(Dragging){if(direction!=Direction.Vertical)container.Left=Math.Max(0,eX+container.Left-DragStart.X);}if(direction!=Direction.Horizo??ntal)container.Top=Math.Max(0,eY+container.Top-DragStart.Y);}};}}publicForm1(){InitializeC组件();ControlMover.Init(this.panel1);ControlMover.Init(this.panel1,ControlMover.Direction.Vertical);如果你想让你的程序在按下ctrl+keys时激活,你需要查看键钩子,然后在键事件中设置一些代码,告诉程序选择所有项目如果你是键钩子的新手,这个非常高级且很难做到,但这里有一个关键钩子的链接。祝你好运!http://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook以上就是C#学习教程:拖拽多个选中的控件分享全部内容,如果大家很有用,需要多了解C#学习教程。希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
