2

Please see the following Code:-

Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
          Parallel.ForEach(Segments.OfType(Of Segment),
                            Sub(segment)
                                Try
                                     segment.DrawLine(e.Graphics)
                                Catch ex As Exception
                                End Try
                            End Sub
                            )
    
         Parallel.ForEach(Ellipses.OfType(Of Ellipse),
                            Sub(ellipse)
                                Try
                                     ellipse.DrawEllipse(e.Graphics)
                                Catch ex As Exception
                                End Try
                            End Sub
                            )
     End Sub

Where the Segment and Ellipse are Classes to draw Lines and Oval Shapes, Segments and Ellipses are the ListOf of the object instances each of which is identified by a Unique Name such as Segment1, Segment2, ..., Ellipse1, Ellipse2...

PictureBox1 has about 362 Line Segments and about 215 Ellipses, all shapes are of varying color, lengths/diameters.

My question - Where PictureBox1 has several shapes such as Segment1, Segment2, ..., Ellipse1, Ellipse2 , Is it possible to Redraw only the Changed Shape identified by its unique Name, instead of Redrawing all Shapes? For example, Can only Segment1 or Ellipse2 be Redrawn?

Raky
  • 625
  • 5
  • 19
  • 1
    When drawing on a default double-buffered device context, your drawing already updates the region that has changed. You can fine-tune this feature handling a custom [BufferedGraphics](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.bufferedgraphics) yourself (see also [Double Buffered Graphics](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/double-buffered-graphics) and [Manually Render Buffered Graphics](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/advanced/how-to-manually-render-buffered-graphics)). – Jimi Feb 01 '22 at 11:26
  • 1
    This implies that your drawing classes must be aware of what drawing region a new shape overlaps and invalidate that section of the drawing, then `Render()` the content. Which leads to handling a form of Layers (a rendering utility common to all graphic applications) – Jimi Feb 01 '22 at 11:26
  • 1
    It's something like this: [How to determine when Rectangles overlap or intersect?](https://stackoverflow.com/a/62948409/7444103), where you determine what existing shapes a new drawing intersects and you draw those sections only (in the example, the *invalidated* parts are just drawn in a different color) – Jimi Feb 01 '22 at 11:34

0 Answers0