Solution according to @Digital_Utopia comment:
This way works with the same flexibility as the windows explorer selector, except that the rectangle is not filled with a color and the rectangle is not 'released' after 'mouse up' 'cause that is not what I need.
Dim SelectionRectangle As Rectangle
Dim InitialPosition As Point
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
' Store the starting coordinates
InitialPosition = e.Location
SelectionRectangle = New Rectangle(InitialPosition.X, InitialPosition.Y, 0, 0)
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
' Me.SuspendLayout()
If e.Button = MouseButtons.Left Then
If (e.Location.X < InitialPosition.X) _
AndAlso (e.Location.Y < InitialPosition.Y) Then ' Top-Left
SelectionRectangle = New Rectangle(e.X,
e.Y,
InitialPosition.X - e.X,
InitialPosition.Y - e.Y)
ElseIf (e.Location.X > InitialPosition.X) _
AndAlso (e.Location.Y < InitialPosition.Y) Then ' Top-Right
SelectionRectangle = New Rectangle(InitialPosition.X,
e.Y,
e.X - InitialPosition.X,
InitialPosition.Y - e.Y)
ElseIf (e.Location.X < InitialPosition.X) _
AndAlso (e.Location.Y > InitialPosition.Y) Then ' Bottom-Left
SelectionRectangle = New Rectangle(e.X,
InitialPosition.Y,
InitialPosition.X - e.X,
e.Y - InitialPosition.Y)
ElseIf (e.Location.X > InitialPosition.X) _
AndAlso (e.Location.Y > InitialPosition.Y) Then ' Bottom-Right
SelectionRectangle = New Rectangle(InitialPosition.X,
InitialPosition.Y,
e.X - InitialPosition.X,
e.Y - InitialPosition.Y)
End If
Me.Invalidate()
End If
' Me.ResumeLayout()
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Using pen As New Pen(Color.Red, 1)
e.Graphics.DrawRectangle(pen, SelectionRectangle)
End Using
End Sub