Properly Repaint a Custom Control
- by serhio
I am doing a custom control, that should be painted like as standard one, but also having a Icon displayed near it.
So, I jet overrided OnPaint like this:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawIcon(theIcon, X1, Y1 - iconSize.Width / 2);
}
Now, everything is OK, but when my control moves, the icon still remains drawn on the ancient place.
What should I add to manage it properly?
In the image we can see that after moving from top to bottom the line(custom control) even is not properly redrawn.
I tried to do
public override void Invalidate()
{
base.Invalidate();
if (Parent != null) {
Parent.Invalidate(new Rectangle(
X1, Y1 - iconSize.Width / 2,
iconSize.Width, iconSize.Height));
}
}
but this does not work - when changing location the Invalidate is not even called.
If it matter the custom control inherits from VisualBasic.PowerPacks.LineShape component.