


























Imports System.Drawing.Point
Public Class Move
Private WithEvents control As System.Windows.Forms.Control
Private mouse_offset As Point
Private frm As Form
Public Sub New(ByVal theControl As System.Windows.Forms.Control, ByVal theForm As Form)
Me.control = theControl '鼠标拖动的控件
Me.frm = theForm '要移动的窗口
End Sub
Private Sub GroupControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles control.MouseDown
mouse_offset = New Point(e.X, e.Y)
End Sub
Private Sub GroupControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles control.MouseMove
If (e.Button = MouseButtons.Left Or e.Button = MouseButtons.Right) Then
Dim mousePos As Point = frm.MousePosition
'获得鼠标偏移量
mousePos.Offset(-mouse_offset.X, -mouse_offset.Y)
'设置窗体随鼠标一起移动
frm.Location = mousePos
End If
End Sub
End Class
使用:
在窗口加载时:
Move move = new Move(this.label1,this)
这样鼠标按住 label1 拖动时,窗口就会移动。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。