急怎样让画出来的线不消失?能帮小弟我修改一下程序吗

急!怎样让画出来的线不消失?能帮我修改一下程序吗?
这是我写的函数
private:
void DrawLine(double mag, double x1, double y1, double x2, double y2)
{
Graphics ^ g;
g=this->pictureBox1->CreateGraphics();
Pen^ MyPen = gcnew Pen(Color::Blue,2.0f );

x1=chX(mag, x1);
x2=chX(mag, x2);
y1=chY(mag, y1);
y2=chY(mag, y2);

g->DrawLine(MyPen, (float) x1, (float) y1,(float) x2, (float) y2);
}

貌似应该用OnPaint来写?但我没找到相应的例子
希望高手能帮着修改一下 不胜感激!

------解决方案--------------------
直接把这个方法放在OnPaint中就可以了
------解决方案--------------------
private: 
void DrawLine(Graphics ^g, double mag, double x1, double y1, double x2, double y2) 

Pen^ MyPen = gcnew Pen(Color::Blue,2.0f ); 

x1=chX(mag, x1); 
x2=chX(mag, x2); 
y1=chY(mag, y1); 
y2=chY(mag, y2); 

g->DrawLine(MyPen, (float) x1, (float) y1,(float) x2, (float) y2); 


在Onpaint里增加一个行:

DrawLine(pe.Graphics, mag, x1, y1, x2, y2);