1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
Option Explicit On
Option Strict On
Public Class SelectionForm
Implements Windows.Forms.IMessageFilter
Private intStartPoint As Point
Private blnShown As Boolean = False
Private blnWaitingMove As Boolean = False
Private iParentForm As Form
Public Sub New(ByVal parentForm As Form)
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.BackColor = System.Drawing.Color.DodgerBlue
Me.ShowInTaskbar = False
Me.Opacity = 0.4
iParentForm = parentForm
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Application.AddMessageFilter(Me)
Me.Hide()
End Sub
Protected Overrides Sub Finalize()
Application.RemoveMessageFilter(Me)
MyBase.Finalize()
End Sub
#Region "Declaration constantes"
Protected Const WM_MOUSEMOVE As Integer = &H200
Protected Const WM_LBUTTONDOWN As Integer = &H201
Protected Const WM_LBUTTONUP As Integer = &H202
#End Region
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Dim mbMouseButton As MouseButtons = MouseButtons.None
Dim intClick As Integer
Select Case m.Msg
Case WM_LBUTTONDOWN
If Not blnShown Then
blnWaitingMove = True
End If
Case WM_LBUTTONUP
If blnShown Then
blnShown = False
Me.Hide()
End If
blnWaitingMove = False
Case WM_MOUSEMOVE
If blnWaitingMove Then
blnShown = True
blnWaitingMove = False
intStartPoint = Control.MousePosition
Me.Location = intStartPoint
Me.Size = New Size(0, 0)
Me.Show()
Else
If blnShown Then
MouseMoveProc()
End If
End If
End Select
If mbMouseButton <> MouseButtons.None Then
Dim meaArgs As New MouseEventArgs(mbMouseButton, intClick, Control.MousePosition.X, Control.MousePosition.Y, 0)
End If
Return False
End Function
Private intMousePreviousPosition As Point = Control.MousePosition
Private Sub MouseMoveProc()
Dim intMouseCurrentPosition As Point = Control.MousePosition
Dim r As Rectangle = iParentForm.RectangleToScreen(iParentForm.ClientRectangle)
If intMouseCurrentPosition.Y > r.Bottom Then
intMouseCurrentPosition.Y = r.Bottom
End If
If intMouseCurrentPosition.Y < r.Top Then
intMouseCurrentPosition.Y = r.Top
End If
If intMouseCurrentPosition.X > r.Right Then
intMouseCurrentPosition.X = r.Right
End If
If intMouseCurrentPosition.X < r.Left Then
intMouseCurrentPosition.X = r.Left
End If
Dim sFormSize As Size
Dim ptFormLocation As Point
Dim XOffset As Integer = intMouseCurrentPosition.X - intStartPoint.X
Dim YOffset As Integer = intMouseCurrentPosition.Y - intStartPoint.Y
If XOffset < 0 Then
ptFormLocation.X = intMouseCurrentPosition.X
sFormSize.Width = -XOffset
Else
ptFormLocation.X = intStartPoint.X
sFormSize.Width = XOffset
End If
If YOffset < 0 Then
ptFormLocation.Y = intMouseCurrentPosition.Y
sFormSize.Height = -YOffset
Else
ptFormLocation.Y = intStartPoint.Y
sFormSize.Height = YOffset
End If
Me.Location = ptFormLocation
Me.Size = sFormSize
End Sub
End Class |
Partager