Can't draw line on win form.

Mar 20 2009 10:45 PM
For some reason my line wont draw on my windows form.  If I place the code in a button event routine it works fine but it won't work when the window loads.  I'm really confused!  thanks:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace testForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();           
        }
    
        public void Form1_Load(object sender, EventArgs e)
        {         
            Pen myPen = new Pen(Color.Red);
            Graphics g = this.CreateGraphics();
            g.DrawLine(myPen, 20, 30, 10, 50);
            //this.Refresh();   //doesn't work if I add this.
        }

    }
}


Answers (3)