【发布时间】:2014-04-03 10:37:31
【问题描述】:
我遇到了三个阻止我的程序运行的错误,我无法弄清楚它们的含义?我一定很愚蠢,因为我什至有我的 C# 书在我旁边,但它仍然没有意义。任何帮助都会很棒。错误是:
Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe' 定义了多个入口点:'WindowsFormsApplication1.Program.Main()'。使用 /main 编译以指定包含入口点的类型。
'WindowsFormsApplication1.Form1.Dispose(bool)':找不到合适的方法来覆盖
Projects\WindowsFormsApplication1\obj\x86\Release\WindowsFormsApplication1.exe' 定义了多个入口点:'Text.Main()'。使用 /main 编译以指定包含入口点的类型。
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
public class Text : Form
{
private Font arialBold24 = new Font("Arial", 24, FontStyle.Bold);
private Font timesItalic14 = new Font("Times New Roman", 14, FontStyle.Italic);
private Font courierPlain18 = new Font("Courier New", 18, FontStyle.Strikeout);
private Font genericSerifBI20 = new Font(FontFamily.GenericSerif, 20, FontStyle.Bold | FontStyle.Italic);
private Font verdanaPlain18 = new Font("Verdana", 18, FontStyle.Regular | FontStyle.Underline);
public Text()
{
Size = new Size(400, 200);
Text = "Text";
BackColor = Color.White;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
int w = (int)g.MeasureString(arialBold24.Name, arialBold24).Width;
int arialStart = (Width - w) / 2;
int otherStart = Width / 4;
int h = DisplayRectangle.Height;
g.DrawString(arialBold24.Name, arialBold24, Brushes.Blue, arialStart, 0);
g.DrawString(timesItalic14.Name, timesItalic14, Brushes.Blue, otherStart, h / 5);
g.DrawString(courierPlain18.Name, courierPlain18, Brushes.Blue, otherStart, 2 * h / 5);
g.DrawString(genericSerifBI20.Name, genericSerifBI20, Brushes.Blue, otherStart, 3 * h / 5);
g.DrawString(verdanaPlain18.Name, verdanaPlain18, Brushes.Blue, otherStart, 4 * h / 5);
base.OnPaint(e);
}
public static void Main()
{
Application.Run(new Text());
}
}
program.cs 代码为:
namespace WindowsFormsApplication1
{
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());
}
}
}
Form1的更新代码:
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
}
}
Program.CS 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Text());
}
}
}
【问题讨论】:
-
根据错误,您的项目中似乎还有一些其他代码 - Form1.cs 和 Program.cs。你也可以发这些吗?您可能可以删除它们或将它们从您的项目中排除以解决错误。
-
查看你的项目,你可能有一个
Program.cs文件,它已经定义了main方法(你放在上面代码末尾的那个)。您可以删除表单类中的 main 方法。
标签: c#