现在的位置: 首页 > 综合 > 正文

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

2014年01月11日 ⁄ 综合 ⁄ 共 1660字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.