Torna al Thread
Public Class Form1
Private mShapeContainer As clsShapeContainer
Private isMouseDown As Boolean = False
Private gFx As Graphics ' backbuffer
Private backBuffer As Bitmap
Private panelGraphics As Graphics
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Genera array di figure
Dim x As Integer = 0, y As Integer = 0
For i As Integer = 0 To 20
mShapeContainer.AddEllipse(x, y)
x += 30
If x >= (Panel1.Width - 30) Then
x = 0
y += 30
End If
If y >= (Panel1.Height - 30) Then
'y = 0
x = 0
End If
Next
Panel1.Invalidate()
End Sub
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
Debug.WriteLine("Panel1.Paint")
If (panelGraphics Is Nothing) Then
panelGraphics = Panel1.CreateGraphics
panelGraphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
End If
'Clear Back Buffer
gFx.Clear(Color.White)
'Draw in back buffer
Draw(gFx)
'Flip backBuffer to screen
panelGraphics.DrawImage(backBuffer, 0, 0)
End Sub
Public Sub Draw(ByRef g As Graphics)
For Each shape As clsShape In mShapeContainer.Shapes
shape.Draw(g)
Next
End Sub
Private Sub Panel1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown
For I As Integer = mShapeContainer.Shapes.Count - 1 To 0 Step -1
With mShapeContainer
If .Shapes(I).Rectangle.Contains(e.Location) Then
.SelectedShape = .Shapes(I)
isMouseDown = True
Exit For
End If
End With
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mShapeContainer = New clsShapeContainer(Me.Panel1)
backBuffer = New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
gFx = Graphics.FromImage(backbuffer)
gFx.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
mShapeContainer.ZoomIn()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
mShapeContainer.ZoomOut()
End Sub
Private Sub Panel1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp
isMouseDown = False
End Sub
Private Sub Panel1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove
If isMouseDown Then
With mShapeContainer
If .SelectedShape IsNot Nothing Then
.SelectedShape.Move(e.Location)
End If
End With
End If
End Sub