I need to call this method, but I can’t find it in any namespace.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.creategraphics.aspx
It says it is in System.Windows.Forms namespace and in System.Windows.Forms.dll.
I am using Visual Studio 2010 and imported the System.Windows.Forms reference into the project.
At the top I made an import (sry, my Java slang) using FORMS = System.Windows.Forms;
Graphics g = FORMS.CreateGraphics(); // error
Error is: “The type or namespace name ‘CreateGraphics’ does not exist in the namespace ‘System.Windows.Forms (are you missing an assembly reference?)”
Thanks for any help.
—EDIT—
I am trying to run the code from the top answer from this post:
GDI+ / C#: How to save an image as EMF?
—EDIT—
With a user’s suggestions, I am trying:
Graphics g = new Graphics();
FORMS.Control a = new FORMS.Control();
g = a.CreateGraphics();
—EDIT—
Never mind, sorry people, I am stupid. Will accept in a second.
This:
Is a namespace alias, not a type alias.
Namespaces do not have methods defined on them.
Additionally,
CreateGraphicsis not static, so can’t be called directly on a type either, only on an instance.Assuming that
myFormis an instance ofForm:In your linked example,
CreateGraphics()is called on thethisinstance implicitly and assumes that the call is within aFormorControltype. So, if you are calling it within a control/form, it will just work.