Exclusive original, drag any control to move any target, drag the control to move the entire form, in the borderless form and its friendly implementation drag and drop the mobile form
http://www.cnblogs.com/vonly/
Only original starter, vonly.net
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Configuration;5 usingSystem.Diagnostics;6 usingSystem.Text;7 usingSystem.Threading;8 usingSystem.Windows.Forms;9 Ten namespaceOnly . Controls One { A Public Partial classdragdrop:component - { - the Private BOOL_enable =false; - -[Browsable (true)] -[Description ("turn on drag function"), Category ("Set")] + Public BOOLEnable - { + Get A { at return_enable; - } - Set - { - if(Value! =_enable) - { in_enable =value; - //Start (value); to NewThread (() = + { -Thread.Sleep ( -); the Start (_enable); * }). Start (); $ Panax Notoginseng } - } the } + A[Browsable (true)] the[Description ("dragging a moving target"), Category ("Set")] + PublicControl Targetcontrol {Get;Set; } -[Browsable (true)] $[Description ("Drag the event source"), Category ("Set")] $ PublicControl SourceControl {Get;Set; } - - the Public voidStart (BOOLEnable =true) - {Wuyi if(SourceControl! =NULL& Targetcontrol! =NULL) the { - if(enable) Wu { -Sourcecontrol.mousedown + =Sourcecontrolonmousedown; AboutSourcecontrol.mousemove + =Sourcecontrolonmousemove; $Sourcecontrol.mouseup + =Sourcecontrolonmouseup; - } - Else - { ASourcecontrol.mousedown-=Sourcecontrolonmousedown; +Sourcecontrol.mousemove-=Sourcecontrolonmousemove; theSourcecontrol.mouseup-=Sourcecontrolonmouseup; - } $ } the } the the Private BOOL_mousedown =false; the Private int_startx =0; - Private int_starty =0; in the Private voidSourcecontrolonmouseup (Objectsender, MouseEventArgs e) the { About_mousedown =false; the } the the Private voidSourcecontrolonmousemove (Objectsender, MouseEventArgs e) + { - if(_mousedown &_enable) the {BayiTargetcontrol.left + = (e.x-_startx); theTargetcontrol.top + = (E.Y-_starty); the } - } - the Private voidSourcecontrolonmousedown (Objectsender, MouseEventArgs e) the { the if(_mousedown = =false) the { -_mousedown =true; the_startx =e.x; the_starty =e.y; the }94 } the } the}
Exclusive original, drag any control to move any target, drag the control to move the entire form