为什么它不能使用“System.Windows.Forms”命名空间? [英] Why does it fail to use "System.Windows.Forms" namespace?

查看:421
本文介绍了为什么它不能使用“System.Windows.Forms”命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其他同事的节目。我想通过调用MessageBox.Show()来添加调试消息。这就是我必须添加一行使用System.Windows.Forms;的原因。在文件的开头。我收到错误

类型或命名空间名称'Forms'在名称空间'System.Windows'中不存在(你错过了程序集引用吗?)

它出什么问题了?我用使用System.Windows.Forms;很好地在同一个项目的另一个文件中,并从其他文件中复制该行。 装配参考是什么意思?我应该怎么做才能解决这个问题?

解决方案

这是因为你不知道使用是什么,只是还没有。如果不了解程序集及其参考,就无法进行任何开发。您开发了一个或多个程序集,另一个可以使用另一个程序集。您可以通过另一个程序集引用一个程序集,或者通过动态加载另一个程序集并使用反射来访问其类型及其成员。动态加载与高级技术有关,但引用是所有技术的基础,因此无需参考即可完成任何操作。



Visual Studio中的引用已完成解决方案资源管理器中的添加引用。要了解引用,您可以从这里开始: https:// msdn。 microsoft.com/en-us/library/8wxf689z%28v=vs.110%29.aspx [ ^ ]。



您还需要了解什么一个模块,以及不同类型的参考,重要的是,GAC和签名,因此,开放密钥加密的想法。请在询问进一步的问题之前自己找到。



作为使用指令(不要混淆使用 语句),它们仅仅有助于缩短程序集级别类型名称的名称。您没有义务使用使用,在所有情况下都可以使用完整类型名称。这只是语法糖。您只需要了解命名空间: https://msdn.microsoft.com/en-us/library/0d941h9d .aspx [ ^ ] 。



-SA a ** hole


首先,你确定它是一个windows表单应用程序?我怀疑它是一个WPF应用程序。



您需要添加对 System.Windows.Forms 的引用。

为此,请转到 Solution Explorer 并右键单击该项目,然后单击添加引用,然后选择 System.Windows.Forms



希望,它有帮助:)


你必须完成项目的参考(项目设置 - 我不要不知道如何使用必要的程序集在你的VS安装中调用它。



在你的情况下你需要集成程序集System.Windows.Forms

I've got a program from other coworker. I would like to add a debugging message by calling MessageBox.Show(). That's the reason I must add one line of "using System.Windows.Forms;" in the beginning of the file. I got error of
"The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)"
What's wrong with it? I used "using System.Windows.Forms;" very well at another file of the same project and copy that line from other file. What does "assembly reference" mean? What should I do to work it out?

解决方案

This is because you don't have a clue what "using" does, just not yet. You cannot do any development at all without understanding assemblies and their reference. You develop one or more assemblies, and one can be used by another one. You can do it be referencing one assembly by another one, or by dynamically loading another assembly and using reflection to access its types and their members. Dynamic loading is related to advanced techniques, but referencing is the basis of all technology, making it impossible to do anything at all without referencing.

Referencing in Visual Studio is done by "Add Reference" in Solution Explorer. For understanding of referencing, you can start here: https://msdn.microsoft.com/en-us/library/8wxf689z%28v=vs.110%29.aspx[^].

You also need to understand what a modules, and different kinds of reference, importantly, GAC and signing, and, hence, the idea open-key cryptography. Please, find it all by yourself before asking further question.

As the "using" directive (not to be mixed up with "using" statement), they merely help to shorten the names of the assembly-level type names. You are not obliged to use "using" at all, can just use full type names in all cases. This is nothing but syntactic sugar. You just need to understand namespaces: https://msdn.microsoft.com/en-us/library/0d941h9d.aspx[^].

—SA a**hole


First of all, are you sure it's a windows form application ? I suspect it to be a WPF application.

You need to add reference to System.Windows.Forms.
To do that go to the Solution Explorer and right click on the project and click on Add Reference and then select System.Windows.Forms.

Hope, it helps :)


You have to complete the References of your Project (Project-Settings - I don't know how it is called in your Installation of VS) with the necessary assemblies.

In your case you need to integrate the assembly "System.Windows.Forms"


这篇关于为什么它不能使用“System.Windows.Forms”命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆