VB.net鼠标控制 控件移动

平头哥哥 2018-01-03 05:39:00
左键拖动,而不是跟随,
...全文
894 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
平头哥哥 2018-01-31
  • 打赏
  • 举报
回复
实现实现啦
清晨曦月 元老 2018-01-04
  • 打赏
  • 举报
回复
不过说实在的,这玩意,有闪烁的可能性比较大。可以尝试一下拖动过程禁止它更新,也可以尝试一下多重缓冲之类的,还可以尝试一下外面套一个panel移动的时候移动这个容器的时候里面的控件不闪烁,总之办法总比困难多。
清晨曦月 元老 2018-01-04
  • 打赏
  • 举报
回复
private withevents ctlTest as new panel private mptEmpty as point=new point(-1,-1) private stPoint as point = mpempty private sub yourfrm_load(s as object,e as eventargs) handles mybase.load ctrTest.size=new size(100,100) ctrtest.location=new point(10,10) ctl.borderstyle=borderstyle. fixedsingle me.controls.add(ctltest) end sub private sub ctlTest_mousedown(s as obj,e as mseve)handles ctltest.mousedown if e.button=mousebuttons.left then stPoint=e.location end if end sub private sub ctrtest_mouseUP(s as obj,e as mseve) handels ctrtest.MouseUp stpoint=mptEmpty end sub private sub ctlTest_mousemove(s ....,e....) handles ctrtext.MouseMove if stPoint<>mptEmpty then ctltest.location +=e.location-stpoint end if end sub 先在左键按下时设置一个标志,我们同时用这个标志表示按下时的位置,然后只要计算现在鼠标位置和按下位置差值就知道移动多少,这样比移动过程中记录上次位置和当前位置要更准确,代码更简洁。鼠标抬起时就恢复这个标志,需要注意的是可能鼠标点到控件左上角0,0,所以标志自定义为-1,-1.移动时判断标志合法就进行移动控件就可以了。

16,549

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧