Torna al Thread
clsShape e clsShapeOval
Public MustInherit Class clsShape
Private mRectangle As Rectangle
Private mSelected As Boolean = False
Private mShapeContainer As clsShapeContainer
Private Shared ZoomFactor As Integer = 5
Public MustOverride Sub Draw(ByRef g As Graphics)
Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal Width As Integer, ByVal Height As Integer, ByRef Parent As clsShapeContainer)
mRectangle = New Rectangle(X, Y, Width, Height)
mShapeContainer = Parent
End Sub
Public Property Selected() As Boolean
Get
Return mSelected
End Get
Set(ByVal value As Boolean)
mSelected = value
End Set
End Property
Public Property Rectangle() As Rectangle
Get
Return mRectangle
End Get
Set(ByVal value As Rectangle)
mRectangle = value
End Set
End Property
Public ReadOnly Property InvalidationRect() As Rectangle
Get
Return New Rectangle(mRectangle.X, mRectangle.Y, mRectangle.Width + 1, mRectangle.Height + 1)
End Get
End Property
Public ReadOnly Property Parent() As clsShapeContainer
Get
Return mShapeContainer
End Get
End Property
Public Sub ZoomIn()
Me.mRectangle.Inflate(ZoomFactor, ZoomFactor)
End Sub
Public Sub ZoomOut()
If Me.mRectangle.Width > (ZoomFactor * 2) AndAlso Me.mRectangle.Height > (ZoomFactor * 2) Then
Me.mRectangle.Inflate(ZoomFactor * -1, ZoomFactor * -1)
End If
End Sub
Public Sub Move(ByVal NewPt As Point)
Dim Region As New Region(Me.InvalidationRect)
Me.mRectangle.Location = NewPt
Region.Union(Me.InvalidationRect)
Parent.Invalidate(Region)
End Sub
End Class
Public Class clsShapeOval
Inherits clsShape
Private Shared mPen As New Pen(Color.Black)
Private Shared mPenSelected As New Pen(Color.Red)
Private mWidth As Integer = 30
Private mHeigth As Integer = 30
Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByRef Parent As clsShapeContainer)
MyBase.New(X, Y, 30, 30, Parent)
End Sub
Public Overrides Sub Draw(ByRef g As System.Drawing.Graphics)
Using mGradiendBrush As New System.Drawing.Drawing2D.LinearGradientBrush(New Rectangle(Rectangle.X, Rectangle.Y, Rectangle.Width, Rectangle.Height), Color.Yellow, Color.Orange, Drawing2D.LinearGradientMode.Vertical)
If Me.Selected Then
g.DrawEllipse(mPenSelected, Rectangle)
Else
g.DrawEllipse(mPen, Rectangle)
End If
g.FillEllipse(mGradiendBrush, Rectangle)
End Using
End Sub
End Class