【问题标题】:winform c# Error 1 'MyGame.MainForm' does not contain a constructor that takes 0 argumentswinform c# Error 1 'MyGame.MainForm' 不包含采用 0 个参数的构造函数
【发布时间】:2014-03-30 02:19:49
【问题描述】:

我得到的错误:

error on line 18 (Applicaiton.Run(new MainForm());
winform c# Error 1 'MyGame.MainForm' does not contain a constructor that takes 0 arguments

如何解决?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace MyGame
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm()); here is where the error is
        }
    }
}

【问题讨论】:

  • 阅读错误应该可以准确地告诉您需要做什么。您正在尝试使用带有 0 个参数的构造函数来创建对象。您没有接受 0 个参数的构造函数。您认为解决方案可能是什么?

标签: c# winforms visual-studio-2010


【解决方案1】:

您需要向您的MainForm 添加一个无参数 构造函数。

public class MainForm : Form
{
    public MainForm()
    {
        InitializeComponent(); // don't forget to call InitializeComponent.
    }

   ...
}

【讨论】:

  • public MainForm(DataRow row) { editRow = row;初始化组件();填充表格(); }
  • 不是无参数构造函数
  • @StillBlessed 不是无参数构造函数。它在签名中有一个参数。 DataRow row
猜你喜欢
  • 2013-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2015-05-04
  • 2011-11-06
  • 2020-02-16
相关资源
最近更新 更多