.net (vb) wpf 模仿QQ 吸附窗体

Imports System.Windows
Imports System.Windows.Forms
Imports System.Drawing
Class MainWindow
        '''

        ''' 拖动窗体
        '''

        ''' 
        ''' 
        Protected Overrides Sub OnMouseLeftButtonDown(ByVal e As MouseButtonEventArgs)
                MyBase.OnMouseLeftButtonDown(e)
                Me.DragMove()
        End Sub
        Private hh As Boolean = False
        Private tt As Boolean = False
        Private timer As New Timer
        Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
                timer.Enabled = True
                AddHandler timer.Tick, AddressOf timertick
        End Sub
        Private Sub timertick()
                If hh = True Then
                        If System.Windows.Forms.Cursor.Position.X >= clien()(0) - 5 And (System.Windows.Forms.Cursor.Position.Y >= Me.Top And System.Windows.Forms.Cursor.Position.Y <= Me.Top + Me.Height) Then
                                Me.Left = clien()(0) - Me.Width
                        End If
                End If
                If tt = True Then
                        If System.Windows.Forms.Cursor.Position.Y <= 1 And (System.Windows.Forms.Cursor.Position.X >= Me.Left And System.Windows.Forms.Cursor.Position.X <= Me.Left + Me.Width) Then
                                Me.Top = 1
                        End If
                End If
        End Sub
        Private Sub MainWindow_MouseEnter(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles Me.MouseEnter            
                        If hh = True Then
                                Me.Left = clien()(0) - Me.Width
                                hh = False
                        End If
                        If tt = True Then
                                Me.Top = 1
                                tt = False
                        End If
        End Sub
        Function clien()
                Return {System.Windows.Forms.Screen.FromPoint(New System.Drawing.Point).Bounds.Width, System.Windows.Forms.Screen.FromPoint(New System.Drawing.Point).Bounds.Height}
        End Function

        Private Sub MainWindow_MouseLeave(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles Me.MouseLeave
                If Me.Top <= 1 And Me.Left + Me.Width >= clien()(0) Then
                        Me.Top = -Me.Height + 5
                        Me.Left = clien()(0) - Me.Width
                        tt = True
                Else
                        hidden()
                        shhtop()
                End If
        End Sub
        Sub hidden()
                If Me.Left + Me.Width >= clien()(0) Then
                        Me.Left = clien()(0) - 5
                        hh=True
                End If
        End Sub
        Sub shhtop()
                If Me.Top <= 1 Then
                        Me.Top = -Me.Height + 5
                        tt = True
                End If
        End Sub
End Class


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值