xnet

 

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 ObjectByVal 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 ObjectByVal 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 拖动时,窗口就会移动。

分类:

技术点:

相关文章:

  • 2021-10-16
  • 2021-08-23
  • 2021-10-09
  • 2021-08-14
  • 2021-10-16
  • 2021-10-01
  • 2021-10-16
  • 2021-10-16
猜你喜欢
  • 2021-10-26
  • 2021-10-01
  • 2021-10-01
  • 2021-10-26
  • 2021-12-08
  • 2021-08-21
  • 2021-04-27
相关资源
相似解决方案