加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 22:47:37 所属栏目:大数据 来源:网络整理
导读:Imports System.WindowsImports System.Windows.FormsImports System.DrawingClass MainWindow ''' ''' 拖动窗体 ''' ''' ''' Protected Overrides Sub OnMouseLeftButtonDown(ByVal e As MouseButtonEventArgs) MyBase.OnMouseLeftButtonDown(e) Me.DragMov
 
 
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读