且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将控件从用户控件复制并移动到窗体; @运行

更新时间:2023-12-06 10:11:28

难怪;您缺少对拖放的任何处理.某些代码应执行控件的移动.假设您有两个父控件oldParentControlnewParentControl,而拖动的控件是movingControl.您的所有活动最终都应以类似
的方式完成
No wonder; you are missing any handling on drag drop. Some code should do the moving of the control. Let''s say you have two parent controls, oldParentControl and newParentControl and the control being dragged, movingControl. All your activity should ultimately be complete with something like

movingControl.Left = //...
movingControl.Top = //... new position in coordinate of the new control when it becomes a new parent

movingControl.Parent = newParentControl; //jumps out of old to new



看看你在做什么!在textBox1_MouseMove中,您每次都会创建一个新控件,然后将其释放,因此最终将对其进行垃圾收集,而无需任何使用.如果这确实是偶数MouseMove的处理程序(顾名思义,但这不是事实),则意味着您多次重复该毫无意义的代码!

这是无法修复的. In将需要阅读有关从头开始拖动和重写代码的所有相关部分的信息.

—SA



Just look what are you doing! In textBox1_MouseMove you create a new control each time and them you loose it, so it will be eventually garbage-collected without any use. If this is really a handler of the even MouseMove (as the name suggests, but this is not a fact yes), it means you repeat this pointless code many, many times!

This is beyond repair. In will need to read about dragging and rewrite all the relevant part of the code from scratch.

—SA