gpt4 book ai didi

c# - 看似简单的 .NET 导入

转载 作者:行者123 更新时间:2023-12-04 16:59:01 25 4
gpt4 key购买 nike

我需要调用这个方法,但是我在任何命名空间中都找不到它。

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.creategraphics.aspx

它说它在 System.Windows.Forms 命名空间和 System.Windows.Forms.dll 中。

我正在使用 Visual Studio 2010 并将 System.Windows.Forms 引用导入到项目中。

在顶部我做了一个导入(sry,我的 Java 俚语)using FORMS = System.Windows.Forms;

Graphics g = FORMS.CreateGraphics(); // error 

错误是:“命名空间‘System.Windows.Forms’中不存在类型或命名空间名称‘CreateGraphics’(您是否缺少程序集引用?)”

谢谢你的帮助。

- -编辑 - -

我正在尝试从这篇文章的最佳答案中运行代码:

GDI+ / C#: How to save an image as EMF?

- -编辑 - -

根据用户的建议,我正在尝试:
Graphics g = new Graphics();
FORMS.Control a = new FORMS.Control();
g = a.CreateGraphics();

- -编辑 - -

没关系,对不起人们,我很愚蠢。一会就接受。

最佳答案

这:

using FORMS = System.Windows.Forms;

是命名空间别名,而不是类型别名。

命名空间没有定义方法。

此外, CreateGraphics不是 静态,因此也不能直接在类型上调用,只能在实例上调用。

假设 myForm Form 的一个实例:
Graphics g = myForm.CreateGraphics();

在您链接的示例中, CreateGraphics()this 上被调用隐式实例并假定调用在 Form 内或 Control类型。因此,如果您在控件/窗体中调用它,它将正常工作。

关于c# - 看似简单的 .NET 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9399076/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com