我正在使用C#.net 4.0 VS 2010。
我在Stackoverflow上复制了以下代码,并确认所有内容都是可以工作的。但是在我的调用“Application.Run(new ShoutBox());”时,我遇到了语法错误,错误为“The type or namespace 'ShoutBox' could not be found.”。
该项目最初构建为控制台应用程序。我最近添加了一个名为ShoutBox的窗体,并将其保存为ShoutBox.cs。我已将代码转移到表单中,因此它不会在控制台上显示,而是在我创建的窗体的文本框中显示。
我错过了什么?我该如何使其工作?
我的Shoutbox表单如下:
我在Stackoverflow上复制了以下代码,并确认所有内容都是可以工作的。但是在我的调用“Application.Run(new ShoutBox());”时,我遇到了语法错误,错误为“The type or namespace 'ShoutBox' could not be found.”。
该项目最初构建为控制台应用程序。我最近添加了一个名为ShoutBox的窗体,并将其保存为ShoutBox.cs。我已将代码转移到表单中,因此它不会在控制台上显示,而是在我创建的窗体的文本框中显示。
我错过了什么?我该如何使其工作?
using System;
using System.Windows.Forms;
namespace ChatApp
{
class ConsoleApplication1
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
//this one works
Application.Run(new Form()); // or whatever
//this one does not work, error on second ShoutBox
Form ShoutBox = new Form();
Application.Run(new ShoutBox());
}
}
}
仅供参考,以下是我的最终工作代码: 此代码创建一个新的 Shoutbox 表单,而不是一个空白表单。
using System;
using System.Windows.Forms;
using ShoutBox; // Adding this
namespace ChatApp
{
class ConsoleApplication1
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Form ShoutBox1 = new ShoutBox.ShoutBox(); //Changing this
Application.Run(ShoutBox1); //Changing this
}
}
}
我的Shoutbox表单如下:
using System
using System.Windows.Forms;
namespace ShoutBox
{
public partial class ShoutBox : Form
{
....