【问题标题】:"Program does not contain a static 'Main' method suitable for an entry point WindowsFormsApp" Error Message“程序不包含适用于入口点 WindowsFormsApp 的静态 'Main' 方法”错误消息
【发布时间】:2020-03-07 10:35:03
【问题描述】:

我正在尝试制作一个表单应用程序,但是当我运行它时出现这样的错误

“程序不包含适用于入口点 WindowsFormsApp 的静态 'Main' 方法”

我该怎么做才能解决这个问题?

【问题讨论】:

  • 您有一个名为 program.cs 的文件吗?应该位于您的项目中。里面应该有一个叫做main的函数你有吗?
  • 这就是它所说的。您必须有一个声明为staticMain 方法。它是入口点(第一个方法运行)。

标签: c# asp.net .net forms


【解决方案1】:

Main 方法是 C# 应用程序的 entry point。 (库和服务不需要 Main 方法作为入口点。)当应用程序启动时,Main 方法是调用的第一个方法。 当这个Main 方法不存在时,它会给出你现在遇到的错误。

program.cs 应该如下所示。

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>


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

请看documentation

【讨论】:

  • 我明白了。谢谢!
  • @ByKizmaz 没问题,编码愉快!
猜你喜欢
  • 1970-01-01
  • 2018-05-15
  • 1970-01-01
  • 2018-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-04
相关资源
最近更新 更多