.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

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...