Help repaiting a Component

Posted by serhio on Stack Overflow See other posts from Stack Overflow or by serhio
Published on 2010-05-03T11:41:15Z Indexed on 2010/05/03 11:48 UTC
Read the original article Hit count: 335

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about gdi+