Redraw a Single Shape or Changed Shape Only Instead of All Shapes

raklali 236 Reputation points
2022-01-31T15:37:47.033+00:00

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...

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?

Request a solution with Sample Code...

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
{count} votes