Grouping pieces of graphics?

myblueocean

Well-known member
Joined
Jun 29, 2007
Messages
161
Location
England
Programming Experience
Beginner
Hi again.

Lets say you have several pieces of small gfx, and you all want them to move together. You would have your code that controls the motion, and then select them all in "paint"?
 
What I did was create an interface something like this:

VB.NET:
Public Interface IDrawingObject

    Event Change(ByVal DrawingObject As IDrawingObject)

    ''' <summary>
    ''' The location of the top-left point of the object
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Location() As Point

    ''' <summary>
    ''' The size of this control. (width x height)
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ReadOnly Property Size() As Size

    ''' <summary>
    ''' The bounded rectange of the control
    ''' </summary>
    ''' <returns>A rectangle</returns>
    ''' <remarks></remarks>
    ReadOnly Property Rectangle() As Rectangle

    ''' <summary>
    ''' The function to paint drawing object.
    ''' </summary>
    ''' <param name="e">The graphics object to paint the object on.</param>
    ''' <remarks></remarks>
    Sub Paint(ByVal e As System.Windows.Forms.PaintEventArgs)

End Interface

You could add/remove interface methods/properties that you need/don't need. You can create a class implementing this interface that contains a list of more idrawingobjects. Then in the paint method, you could loop through each of its constituent objects and run each of the paint methods.

In the Set of the Location property, you could loop through each constituent object and also modify its location.

Then, you can handle whatever paint method you wish to handle like this:
VB.NET:
    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        MyComplexDrawingObject.Paint(e.Graphics)
    End Sub
 
Back
Top