Ciao a tutti,
sto sviluppando una piccola applicazione di test, che mi permetta di disegnare tramite GDI+ dei cerchi su una form, e di poterli spostare con il mouse. Insomma qualcosa di davvero semplice.
Premetto che ho già tentato la strada di usare i nuovi controlli presenti in Visual Basic Power Pack 3.0 ma senza successo (o meglio, avevo li stessi problemi di flickering durante lo spostamento col mouse che ho tutt'ora).
Brevemente, ho una classe clsShape (classe base per tutte le forme che dovrò disegnare) una classe clsShapeOval (che rappresenta un cerchio, derivata da shape) ed una classe clsShapeContainer ( che rappresenta un contenitore di Shape)
posto il codice, è un po' lungo, ma magari rende più chiare le cose
clsShapeContainer
Public Class clsShapeContainer
Private mShapes As New List(Of clsShape)
Private mShapeSelected As clsShape
Private mParent As System.Windows.Forms.Control
Public Sub New(ByRef Parent As System.Windows.Forms.Control)
mParent = Parent
End Sub
Public Property SelectedShape() As clsShape
Get
Return mShapeSelected
End Get
Set(ByVal value As clsShape)
'Deseleziona vecchia shape
DoUnSelect()
DoSelect(value)
End Set
End Property
Public Property Shapes() As List(Of clsShape)
Get
Return mShapes
End Get
Set(ByVal value As List(Of clsShape))
mShapes = value
End Set
End Property
Public Sub AddEllipse(ByVal X As Integer, ByVal Y As Integer)
mShapes.Add(New clsShapeOval(X, Y, Me))
End Sub
Public Sub ZoomIn()
For Each shape As clsShape In Shapes
shape.zoomIn()
Next
mParent.Invalidate()
End Sub
Public Sub ZoomOut()
For Each shape As clsShape In Shapes
shape.ZoomOut()
Next
mParent.Invalidate()
End Sub
Private Sub DoUnSelect()
If Me.mShapeSelected IsNot Nothing Then
mShapeSelected.Selected = False
mParent.Invalidate(mShapeSelected.InvalidationRect)
mShapeSelected = Nothing
End If
End Sub
Private Sub DoSelect(ByRef shape As clsShape)
If shape IsNot Nothing Then
shape.Selected = True
Me.mShapeSelected = shape
BringToFront(shape)
mParent.Invalidate(mShapeSelected.InvalidationRect)
End If
End Sub
Public Sub Invalidate(ByVal Region As Region)
mParent.Invalidate(Region)
End Sub
Public Sub BringToFront(ByRef shape As clsShape)
Dim i As Integer = Shapes.IndexOf(shape)
Shapes.Add(Shapes(i))
Shapes.Remove(Shapes(i))
End Sub
End Class
Form
Durante lo spostamento del mouse, dopo aver selezionato uno dei cerchi, lo shape che sto spostando sfarfalla vistostamente.
Chi mi sa aiutare ? Ho già tentato di implementare un back buffer, ma senza miglioramenti eviedenti