Firstly, when you create a graphics item, you are responsible for destroying it. They are a (very) finite resource, and you must not create them, use them and discard them as the whole system will run out, well before the GC gets round to disposing of them for you. The best way is to put them in a
using
block:
using(Graphics g = pictureBox1.CreateGraphics())
{
g.Clear(Color.Transparent);
Pen p = new Pen(Color.Red, 2.0f);
for (int n = 1; n <= 50; n++)
{
g.DrawLine(p, n * (Cursor.Position.X), Cursor.Position.Y - 30.0f, n * (Cursor.Position.X), Cursor.Position.Y + 30.0f);
}
}
Secondly, don't do what you are trying to do. A Picture box is a dumb animal, and when you manually erase it's content as you do in the example you gave it doesn't know to re-draw it. You can force it to redraw it's picture, but then it will overwrite your lines.
Instead, use a Panel, and handle the Paint event. Draw the picture yourself - using the Graphics property of the PaintEventArgs "e" so you don't have to worry about destroying it - then on the same graphics context draw your lines. Simples!