I don't see where you have set g to an instance of Graphics. Usually you use a Graphics inside a Paint event handler (where the graphics object is in PaintEventArgs parameter) or you can create a Graphics object using the CreateGraphics method of a Control/Form.