Properly Repaint a Custom Control
Posted
by serhio
on Stack Overflow
See other posts from Stack Overflow
or by serhio
Published on 2010-03-04T13:55:08Z
Indexed on
2010/03/08
9:06 UTC
Read the original article
Hit count: 222
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.
© Stack Overflow or respective owner