积极答复者
类型“diy21.Form1”已经包含“components”的定义 F:\C#\C#DIY\diy21\diy21\Form1.cs 20 49 diy21

问题
-
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;namespace diy21
{
/// <summary>
/// Summary description for Form.
/// </summary>
public partial class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txt_input;
private System.Windows.Forms.Button btn_ok;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;public Form1()
{
//
//Required for Windows Form Designer sypport
//
InitializeComponent();
//
//TODO:Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}#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.txt_input = new System.Windows.Forms.TextBox();
this.btn_ok = new System.Windows.Forms.Button();
this.SuspendLayout();
//
//txt_input
//
this.txt_input.Location = new System.Drawing.Point(88, 64);
this.txt_input.Name="txt_input";
this.txt_input.TabIndex=0;
this.txt_input.Text = "朋友,您好!";
//
//btn_ok
//
this.btn_ok.Location = new System.Drawing.Point(104, 128);
this.btn_ok.Name = "btn_ok";
this.btn_ok.TabIndex = 1;
this.btn_ok.Text = "我想说";
this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
//
//Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls = new AddRange(new System.Windows.Forms.Control[] {
this.btn_ok,
this.txt_input
});
this.Name = "Form1";
this.Text = "我的第一个Windows应用程序";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btn_ok_Click(object sender, System.EventArgs e)
{
MessageBox.Show(txt_input.Text, "Hello");
}
}
}一个很简单的入门程序啊、但是报错了、不会解决了、大家救救我啊、、
错误 1 类型“diy21.Form1”已经包含“components”的定义 F:\C#\C#DIY\diy21\diy21\Form1.cs 20 49 diy21
错误 2 类型“diy21.Form1”已定义了一个名为“Dispose”的具有相同参数类型的成员 F:\C#\C#DIY\diy21\diy21\Form1.cs 35 33 diy21
错误 3 类型“diy21.Form1”已定义了一个名为“InitializeComponent”的具有相同参数类型的成员 F:\C#\C#DIY\diy21\diy21\Form1.cs 52 22 diy21- 已编辑 Sheng Jiang 蒋晟Moderator 2010年4月28日 19:12 标题含糊
- 已更改类型 小铭 2010年5月2日 9:06
答案
-
应该是您直接复制粘贴了代码。注意您给出的代码是 partial class,Windows Forms Designer 可能已经为您生成了 InitializeComponents() 和 Dispose() 方法 (在 Form.designer.cs),把这两个方法去掉后再编译试试看。或者直接删除 Form.designer.cs。
Mark Zhou- 已标记为答案 KeFang Chen 2010年5月5日 1:13
-
你好!
没关系,你可以参考这个文档资料:
http://msdn.microsoft.com/zh-cn/library/5b13a7k4%28VS.80%29.aspx
如果遇到问题我们可以继续交流啊,希望学习进步!
周雪峰- 已标记为答案 KeFang Chen 2010年5月5日 1:13
全部回复
-
应该是您直接复制粘贴了代码。注意您给出的代码是 partial class,Windows Forms Designer 可能已经为您生成了 InitializeComponents() 和 Dispose() 方法 (在 Form.designer.cs),把这两个方法去掉后再编译试试看。或者直接删除 Form.designer.cs。
Mark Zhou- 已标记为答案 KeFang Chen 2010年5月5日 1:13
-
你好!
没关系,你可以参考这个文档资料:
http://msdn.microsoft.com/zh-cn/library/5b13a7k4%28VS.80%29.aspx
如果遇到问题我们可以继续交流啊,希望学习进步!
周雪峰- 已标记为答案 KeFang Chen 2010年5月5日 1:13