这篇文章主要介绍VB.NET如何拖动窗体,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
这是一个使用VB.NET拖动窗体中的拖动无边框的窗体方法,以下为源代码,朋友们可以参考一下
Private oOriginalRegion As
Region = Nothing' 用于窗体移动
Private bFormDragging As
Boolean = FalsePrivate oPointClicked As Point
Private Sub Form1_MouseDown
(ByVal sender As Object, ByVal
e As System.Windows.Forms.
MouseEventArgs) Handles
MyBase.MouseDownMe.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.oPoint
Clicked.X * -1, _
(Me.oPointClicked.Y + _
SystemInformation.CaptionHeight + _
SystemInformation.BorderSize.
Height) * -1)
' 移动窗体
Me.Location = oMoveToPoint
End If
End Sub
以上是“VB.NET如何拖动窗体”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网行业资讯频道!