Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the default constructor of System.Drawing.Graphics removed?

When I try to create an object of Graphics, why doesn't the following work?

System.Drawing.Graphics graphicsObj = new System.Drawing.Graphics();

(I am aware that I could create a private System.Windows.Forms.Panel Obj; and then do CreateGraphics() if I wanted it to work)

I tried to find a custom constructor for Graphics, but I couldn't find one. Where did Microsoft define it, or how did it block it?

like image 997
Albert Iordache Avatar asked May 21 '10 14:05

Albert Iordache


1 Answers

Default constructors are only created by the C# compiler if there are no other declared constructors. In this case it looks like all constructors are internal or private. Basically you don't construct one yourself - you ask for one from an image, control or whatever, or get given one for paint events etc.

like image 172
Jon Skeet Avatar answered Sep 19 '22 17:09

Jon Skeet