Help repaiting a Component
- by serhio
I am working with Microsoft.VisualBasic.PowerPacks.RectangleShape, but the question is common for components or controls in general.
I added to a TextRectangleShape : RectangleShape a Text property:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim f As Font = Me.Font
Dim g As Graphics = e.Graphics
Dim textRect As Rectangle = New Rectangle(Me.Location, Me.Size)
Using br As New SolidBrush(Me._TextColor)
g.DrawString(_Text, f, br, textRect)
End Using
End Sub
Now when I move this control the text does not disappear from the former location.
Maybe I could invalidate each time the Parent in the OnPaint, but if this is not a good solution if the parent has a time consuming repaint logic or I have a lot of my custom component moving at the same time.
How do I properly repaint the component?