Hier eine Demo mit 4 Eckhandler + Cursor (Ein-Aus: Maustaste rechts)
Imports System.Drawing.Drawing2D
Public Class Form1
Dim Fo As New Font("Arial", 12, FontStyle.Bold)
Dim WithEvents Pb As New PictureBox With {.Dock = DockStyle.Fill, .Parent = _
Me}
Dim hgrund As Bitmap = SystemIcons.Shield.ToBitmap
Dim picList As New List(Of MyPicture) 'Bilderliste
Dim hrList As New List(Of Rectangle) 'Handler-Rechtecke
Dim loc As Point, rec, rec2 As Rectangle
Dim hp As Int32 = 0, handler, movh As Boolean
Dim cur As New List(Of Cursor)({Cursors.SizeAll, Cursors.PanNW, _
Cursors.PanNE, Cursors.PanSW, Cursors.PanSE})
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ClientSize = New Size(800, 800)
For y = 200 To 400 Step 100
picList.Add(New MyPicture With {.Img = _
SystemIcons.Warning.ToBitmap, .Bounds = New Rectangle(225, y, 64, _
64)})
picList.Add(New MyPicture With {.Img = SystemIcons.Error.ToBitmap, _
.Bounds = New Rectangle(375, y, 64, 64)})
picList.Add(New MyPicture With {.Img = Me.Icon.ToBitmap, .Bounds = _
New Rectangle(525, y, 64, 64)})
Next
End Sub
Private Sub Pb_MouseDown(sender As Object, e As MouseEventArgs) Handles _
Pb.MouseDown
For i = picList.Count - 1 To 0 Step -1
rec = picList(i).Bounds
If rec.Contains(e.Location) Then
loc = e.Location
picList.Add(picList(i)) 'Auswahl auf Top setzen
picList.RemoveAt(i)
SetHandler()
Exit For
End If
Next
If handler Then
Pb.Cursor = Cursors.SizeAll
For i = hrList.Count - 1 To 0 Step -1
If hrList(i).Contains(e.Location) Then
loc = e.Location
Pb.Cursor = cur(i)
hp = i
movh = True
rec = picList(picList.Count - 1).Bounds
rec2 = rec
Exit Sub
End If
Next
End If
movh = False
End Sub
Private Sub SetHandler()
Dim re As Rectangle = picList(picList.Count - 1).Bounds
hrList.Clear()
hrList.Add(re)
hrList.Add(New Rectangle(re.X - 15, re.Y - 15, 15, 15))
hrList.Add(New Rectangle(re.Right, re.Y - 15, 15, 15))
hrList.Add(New Rectangle(re.X - 15, re.Bottom, 15, 15))
hrList.Add(New Rectangle(re.Right, re.Bottom, 15, 15))
End Sub
Private Sub Pb_MouseUp(sender As Object, e As MouseEventArgs) Handles _
Pb.MouseUp
If e.Button = MouseButtons.Right Then
handler = Not handler
Pb.Invalidate()
End If
movh = False
Pb.Cursor = Cursors.Default
End Sub
Private Sub Pb_MouseMove(sender As Object, e As MouseEventArgs) Handles _
Pb.MouseMove
If movh AndAlso e.Button = MouseButtons.Left Then
Select Case hp
Case 0 : picList(picList.Count - 1).Bounds = New Rectangle(New _
Point(rec.X + (e.X - loc.X), rec.Y + e.Y - loc.Y), rec.Size)
Case 1
rec.X = rec2.X + (e.X - loc.X) : rec.Width = rec2.Width + ( _
loc.X - e.X)
rec.Y = rec2.Y + (e.Y - loc.Y) : rec.Height = rec2.Height + _
(loc.Y - e.Y)
Case 2
rec.Width = rec2.Width - (loc.X - e.X) : rec.Height = _
rec2.Height + (loc.Y - e.Y)
rec.Y = rec2.Y - (loc.Y - e.Y)
Case 3
rec.X = rec2.X + (e.X - loc.X) : rec.Width = rec2.Width + ( _
loc.X - e.X)
rec.Height = rec2.Height + (e.Y - loc.Y)
Case 4
rec.Width = rec2.Width + (e.X - loc.X)
rec.Height = rec2.Height + (e.Y - loc.Y)
End Select
If hp > 0 Then picList(picList.Count - 1).Bounds = rec
SetHandler()
Pb.Invalidate()
End If
End Sub
Private Sub Pb_Paint(sender As Object, e As PaintEventArgs) Handles Pb.Paint
e.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor
e.Graphics.DrawImage(hgrund, 0, 0, Pb.Width, Pb.Height)
For Each pic In picList
e.Graphics.DrawImage(pic.Img, pic.Bounds)
Next
If handler Then
Using p As New Pen(Brushes.White, 3)
For i = 0 To hrList.Count - 1
e.Graphics.DrawRectangle(p, hrList(i))
e.Graphics.DrawRectangle(Pens.Black, hrList(i))
Next
End Using
End If
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
Pb.Invalidate()
End Sub
End Class
Public Class MyPicture
Public Img As Bitmap
Public Bounds As Rectangle
End Class MfG GPM |