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 120 121 122 123 124 125 126
|
'ajouter
' 3 boutons radio pour les 3 enums
' un label et un panel de test
Public Class Form2
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler Me.Label1.MouseDown, AddressOf Control_MouseDown
AddHandler Me.Label1.MouseMove, AddressOf Control_MouseMove
AddHandler Me.Label1.MouseUp, AddressOf Control_MouseUp
AddHandler Me.Panel1.MouseDown, AddressOf Control_MouseDown
AddHandler Me.Panel1.MouseMove, AddressOf Control_MouseMove
AddHandler Me.Panel1.MouseUp, AddressOf Control_MouseUp
End Sub
Private oldForeColor As Color
Private selectionForeColor As Color = Color.LightBlue
Private IsDown As Boolean = False
'deplacement relatif
Dim ptDown As Point = New Point(-1, -1)
Private mEdge As EdgeEnum = EdgeEnum.None
'memorise Bounds du control
Private rc As Rectangle = Rectangle.Empty
'MISE EN CACHE DE CONTROL.BOUNDS
Private cachedRect As Rectangle = Rectangle.Empty
Private Sub Control_MouseDown(ByVal sender As System.Object, ByVal e As MouseEventArgs)
Dim c As Control = CType(sender, Control)
If e.Button = MouseButtons.Left Then
IsDown = True
ptDown = e.Location
oldForeColor = c.BackColor
rc = c.Bounds
c.BackColor = selectionForeColor
'UN NEW EST NECESSAIRE SINON CHAQUE MAJ DE rc
'AFFECTERAIT cachedRect
cachedRect = New Rectangle(rc.Location, New Size(rc.Width, rc.Height))
End If
End Sub
Private Sub Control_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
Dim c As Control = CType(sender, Control)
Dim dx As Integer = e.X - ptDown.X
rc = c.Bounds
If IsDown And mEdge <> EdgeEnum.None And e.Button = MouseButtons.Left Then
Select Case mEdge
Case EdgeEnum.Left
If rc.X + e.X < cachedRect.Right Then 'limite droite
rc.Offset(dx, 0)
rc.Width = Math.Max(rc.Width - dx, 20) ' tolerance sur le width mini
c.Bounds = rc
End If
Case EdgeEnum.Right
If rc.X + e.X > 0 Then 'limite gauche(left =0 car e.x est exprime par rapport à lu-meme)
rc.Width = Math.Max(e.X, 20)
c.Bounds = rc
End If
End Select
End If
End Sub
Private Sub Control_MouseUp(ByVal sender As System.Object, ByVal e As MouseEventArgs)
Dim c As Control = CType(sender, Control)
IsDown = False
c.BackColor = oldForeColor
'RESET cachedRect
cachedRect = Rectangle.Empty
End Sub
Private Sub radioLeft_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radioLeft.CheckedChanged,
radioRight.CheckedChanged, radioNone.CheckedChanged
Dim c As RadioButton = CType(sender, RadioButton)
Select Case c.Name
Case "radioLeft"
mEdge = EdgeEnum.Left
Case "radioRight"
mEdge = EdgeEnum.Right
Case "radioNone"
mEdge = EdgeEnum.None
End Select
End Sub
Public Enum EdgeEnum
Left
Right
None
End Enum
End Class |
Partager