Sometimes I get also problems like that.
But I've solved it to do this:
First, add a
Paint
event handler to your control (do this in the constructor):
this.Paint += UserControl1_Paint;
Then, add the
UserControl1_Paint
method:
void UserControl1_Paint(object sender, PaintEventArgs e)
{
Pen pen1 = new Pen(Color.Blue, _LineWidth);
e.Graphics.DrawLine(pen1, 10, 10, 100, 100);
}
If you do that, you can remove the
PaintLine
method.
Also, you don't need to create a
Graphics
object, use
e.Graphics
.
If the
LineWidth
property is changed, change the
PaintLine();
line into this:
this.Refresh();
Then the method
UserControl1_Paint
will be invoked automatically.
Hope this helps.