错误2类型'WindowsForms2012Snowman.WindowsForms2012SnowmanForm1'已经定义了一个名为'Dispose'的成员,其成员具有相同的参数类型

时间:2014-04-22 22:29:14

标签: c#

另一个错误,错误1类型' WindowsForms2012Snowman.WindowsForms2012SnowmanForm1'已包含'组件的定义' c:\ users \ se3449 \ documents \ visual studio 2012 \ Projects \ WindowsFormsApplication3 \ WindowsFormsApplication3 \ Program.cs 19 50 WindowsFormsApplication3

namespace WindowsFormsApplication2
{
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>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (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.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Text = "Form1";
    }

    #endregion
}
}

//Form.cs C# program for Snowman.
//CIS180-101, current date in form of MM-DD-YYYY
//YourFirstNameYourLastName
//Program demonstrates a basic windows application using a single form.
//The form was created using IDE and all code is in Paint.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsForms2012Snowman
{
public partial class WindowsForms2012SnowmanForm1 : Form
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.ComponentModel.Container components = null;
        public Form1()
        {
            InitializeComponent();
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        #region Windows Form Designer generated code
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        private void InitialieComponent()
        {
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(456, 273);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
        }
        #endregion
        ///The main entry point for the application.
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }
        private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            const int MID = 150;
            const int TOP = 50;

            this.BackColor = Color.Cyan;            //Background color
            this.Width = 310;                       //Width (optional)
            this.Height = 260;                      //Height (optional)
            this.Text = "Simple Graphics Snowman";  //Title (optional)

            //Pens and brushe: pens for draws; brushes for fillas
            Pen blue = new Pen(Color.Blue);
            Pen yellow = new Pen(Color.Yellow);
            Pen white = new Pen(Color.White);
            Pen black = new Pen(Color.Black);
            Brush brWhite = white.Brush;
            Brush brBlack = black.Brush;
            Graphics g = e.Graphics;    //Get graphics tool kit

            //Draw snowman
            g.DrawRectangle(blue, 0, 175, 300, 50);                                     //sky
            g.DrawEllipse(yellow, -40, -40, 80, 80);                                       //sun
            g.FillEllipse(brWhite, MID - 20, TOP, 40, 40);                             //head
            g.FillEllipse(brWhite, MID - 35, TOP + 35, 70, 50);                     //top 
            g.FillEllipse(brBlack, MID - 50, TOP + 80, 100, 60);                   //bot.
            g.FillEllipse(brBlack, MID - 10, TOP + 10, 5, 5);                         //l. eye
            g.FillEllipse(brBlack, MID + 5, TOP + 10, 5, 5);                          //r. eye
            g.DrawArc(black, MID - 10, TOP + 20, 20, 10, -190, -160);       //Arms
            g.DrawLine(black, MID - 25, TOP + 60, MID - 50, TOP + 40);
            g.DrawLine(black, MID + 25, TOP + 60, MID + 50, TOP + 60); //Hat: Brim, top  
            g.DrawLine(black, MID - 20, TOP + 5, MID + 20, TOP + 5);
            g.FillRectangle(brBlack, MID - 15, TOP - 20, 30, 25);
        }
    }
}
}

1 个答案:

答案 0 :(得分:0)

您在底部片段中为components定义了DisposedForm1,并在上部片段中再次为Form1的部分类。

C#编译器会将这两个部分合并为一个类定义,然后警告您已经多次定义。

修复它并编译。