关闭

鼠标移动窗体或点住控件移动窗体

623人阅读 评论(0) 收藏 举报

''''#############     注意        #######################
''''
'''            转载请保留原版信息及源码        '''''''
''''
'''
'''     
http://25hour.netyi.org
''''
'''''
''''####################################################
'''类功能:鼠标移动窗体或点住控件移动窗体
'''源码出自:贰伍小时 (25hour   kevery) (写)
'''日期:2005-05-20
'''开发工具:.NET  
'''语言:VB.NET
'''使用方法
'''在窗体form1类中定义该类的对像并实例化
'''如:   dim Mouse_M as new Mouse(me)  ''即可,当你点住窗体移动鼠标时,窗体会跟住移动
Public Class Mouse
#Region "移动"
    Dim FormX, FormY As Integer
    Dim FormBool As Boolean = False
    Friend WithEvents FormMouse As System.Windows.Forms.Control
    Sub New(ByVal OB As Object)
        FormMouse = OB
    End Sub
    Public Sub Mouse_Down(ByVal MouseE As System.Windows.Forms.MouseEventArgs)
        FormX = MouseE.X
        FormY = MouseE.Y
        FormBool = True
    End Sub
    Public Sub Mouse_Up()
        FormBool = False
    End Sub
    Public Sub Mouse_Move(ByVal MouseE As System.Windows.Forms.MouseEventArgs)
        If FormBool = True Then
            Dim Fx, Fy As Integer
            Fx = MouseE.X
            Fy = MouseE.Y
            Try
                FormMouse.Location = New Point(FormMouse.Location.X + (Fx - FormX), FormMouse.Location.Y + (Fy - FormY))

            Catch ex As Exception

            End Try
        End If
    End Sub

#End Region

    Private Sub FormMouse_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormMouse.MouseDown
        Mouse_Down(e)
    End Sub

    Private Sub FormMouse_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormMouse.MouseUp
        Mouse_Up()
    End Sub

    Private Sub FormMouse_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FormMouse.MouseMove
        Mouse_Move(e)
    End Sub
End Class

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:36092次
    • 积分:643
    • 等级:
    • 排名:千里之外
    • 原创:25篇
    • 转载:3篇
    • 译文:0篇
    • 评论:12条
    最新评论
    KJ-NET