C#:命名空间'Forms'在名称空间'System.Windows'

时间:2016-04-06 04:28:41

标签: c# forms namespaces

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

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

我刚刚添加了“using 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:对不起,如果我的问题有错误,我的英语不是很好。

非常感谢。

1 个答案:

答案 0 :(得分:0)

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

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");
相关问题