【问题标题】:C#: Namespace ' Forms ' does not exist in the namespace ' System.Windows ' [duplicate]C#:命名空间“Forms”在命名空间“System.Windows”中不存在[重复]
【发布时间】:2016-07-26 06:55:19
【问题描述】:

我有一个网络应用程序,我想向用户显示一条消息,所以我搜索了网络并找到了 System.Windows.Forms,但是当我尝试使用它时,我收到以下错误:

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

我刚刚添加了“使用 System.Windows.Forms”语句并右键单击了解决方案,转到“添加引用”并选中“System.Windows.Forms”项。 对于 Visual Studio,没有错误,所以我编译了解决方案,但是当我尝试打开该表单时,我得到了错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AcademiaSparta;
using System.Windows.Forms;

namespace AcademiaSpartaWeb
{
    public partial class Registrarse : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Hola");
        }
    }
}

我搜索了 3 个小时,但找不到答案。

PS:对不起,如果我的问题有语法错误,我的英语不是很好。

非常感谢。

【问题讨论】:

  • 您是否尝试在客户端的浏览器中显示消息框?
  • 好吧,System.Windows.Forms 是一个完全错误的方法......
  • 您想使用警报。不幸的是,它不如 Windows 窗体好。
  • System.Windows.Forms 用于桌面应用程序,在创建 Web 应用程序时对您没有任何好处。如果你想在浏览器上显示一个消息框,你需要使用 Javascript 的 Alert。

标签: c# forms namespaces


【解决方案1】:

或者在你的解决方案中创建这样的方法:

public static class MessageBox {
    public static void Show(this Page Page, String Message) {
       Page.ClientScript.RegisterStartupScript(
          Page.GetType(),
          "MessageBox",
          "<script language='javascript'>alert('" + Message + "');</script>"
       );
    }
}

然后你可以像这样使用它:

MessageBox.Show("Hola");

【讨论】:

  • 感谢 Vikram Bose 的回答。我理解 System.Windows.Forms 的错误。
猜你喜欢
  • 2022-07-07
  • 2022-01-11
  • 2014-03-04
  • 2016-02-11
  • 2011-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多