I have a Windows Forms application in C# with drawing panel and a button - for drawing a line.
When you click the button, you can draw a line for 2 random points.
Whenever you want to redraw (in your code) you should call panelinvalidate drawPanel.Invalidate().
When you finish mouse moving and release the button
private void drawPanel_MouseUp(object sender, MouseEventArgs e)
{
onMouseUpFlag = true;
drawPanel.Invalidate();
}
And at the end I would suggest to use this code in your drawPanel_Paint instead of that of yours . You should use Graphics provided by an EventArgs, not create new one.
private void drawPanel_Paint(object sender, PaintEventArgs e)
{
if (onMouseUpFlag)
{
e.Graphics.DrawLine(p, ps, pe);
}
}