首页 > 编程 > .NET > 正文

VB.NET 拖动无边框的窗体

2024-07-10 13:01:14
字体:
来源:转载
供稿:网友

******************************************
private ooriginalregion as region = nothing
' 用于窗体移动
private bformdragging as boolean = false
private opointclicked as point

'******************************************

private sub form1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles mybase.mousedown

me.bformdragging = true
me.opointclicked = new point(e.x, e.y)

end sub
'******************************************

private sub form1_mouseup(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles mybase.mouseup
me.bformdragging = false

end sub
'******************************************

private sub form1_mousemove(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles mybase.mousemove
if me.bformdragging then
dim omovetopoint as point
' 以当前鼠标位置为基础,找出目标位置
omovetopoint = me.pointtoscreen(new point(e.x, e.y))
' 根据开始位置作出调整
omovetopoint.offset(me.opointclicked.x * -1, _
(me.opointclicked.y + _
systeminformation.captionheight + _
systeminformation.bordersize.height) * -1)
' 移动窗体
me.location = omovetopoint
end if

end sub


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表