不包含静态'Main'方法,适用于Windows窗体中的入口点

本文关键字:窗体 Windows 入口 方法 静态 包含 Main 适用于 | 更新日期: 2023-09-27 18:02:14

我正在尝试制作一些图书馆软件(用于分配),但不断得到此错误,尽管它在20分钟前工作。

我最初从Windows窗体应用程序做这个,但不知道哪里出错了:(

我有一种感觉,这是一个"简单"的错误来修复。但它的答案还是影射了我。

Program k:'LibrarySoftware'Library_Software'Library_Software'obj'Debug'Library_Software.exe' does not contain a static 'Main' method suitable for an entry point


Library.cs 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Library_Software
{
    public partial class Form1 : Form 
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void lblYear_Click(object sender, EventArgs e)
        {
        }
        private void btnAddBook_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms["Add_Book"] != null)
            { 
                //you can use closing or hiding method
                Application.OpenForms["Add_Book"].Close();
                //Application.OPenForms["Add_Book"].Hide();
            }
            Add_Book B = new Add_Book();
            B.Show();
        }
        private void lblNarrator_Click(object sender, EventArgs e)
        {
        }
        private void cbxBookType_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void btnLoadBooks_Click(object sender, EventArgs e)
        {
        }
        private void btnDeleteBook_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms["Form2"] != null)
            {
                //you can use closing or hiding method
                Application.OpenForms["Form2"].Close();
                //Application.OPenForms["Add_Book"].Hide();
            }
            Form2 D = new Form2();
            D.Show();
        }
    }
}

如果有其他错误请指出

不包含静态'Main'方法,适用于Windows窗体中的入口点

您的项目中缺少一个主方法。表单不会初始化自己,它必须在作为应用程序入口点的方法中初始化。在VS2012中创建一个新的winforms项目生成这样的类:

    static class Program {
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
    }

如果你在你的项目中没有一个类文件"Program.cs",创建一个并添加我刚才提供的代码。然后应用程序应该按预期运行。我猜你是不小心删了这门课之类的。

您需要将表单文件放入WindowsFormsApplication项目。

在你的visual studio中:-进入文件->新建项目—搜索"Windows Forms Application"-填写文本框,点击完成

现在你可以按F5启动应用程序,最终将你的库表单添加到