C# ';处置';C语言中的歧义错误#

C# ';处置';C语言中的歧义错误#,c#,dispose,C#,Dispose,我有以下代码: public partial class Painter : Form { private System.ComponentModel.Container Components = null; private const int m_intDIAMETER = 8; private const int m_intMOUSEUP_DIAMETER = 4; private Graphics m_objGr

我有以下代码:

public partial class Painter : Form
    {
        private System.ComponentModel.Container Components = null;

        private const int m_intDIAMETER = 8;

        private const int m_intMOUSEUP_DIAMETER = 4;

        private Graphics m_objGraphic;

        private bool m_binShouldPaint = false;

        private bool m_binShouldErase = false;



        public Painter()
        {
            InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                    //components = null;
                }
            }
            base.Dispose(disposing);
        }
        static void Main()
        {
            Application.Run(new Painter());
        }


        private void Form1_Load(object sender, EventArgs e)
        {
            m_objGraphic = CreateGraphics();

        }

        private void Painter_MouseDown(object sender,System.Windows.Forms.MouseEventArgs e)
        {
            //m_objGraphic.FillEllipse(new SolidBrush(Color.HotPink), e.X, e.Y, m_intDIAMETER, m_intDIAMETER);
            //m_binShouldPaint = true;

            if (e.Button == MouseButtons.Left)
            {
                m_binShouldPaint = true;
            }
            else if (e.Button == MouseButtons.Right)
            {
                m_binShouldErase = true;
            }
        }
在编译时,我的调试器生成以下错误:

Error   1   Type 'Painter.Painter' already defines a member called 'Dispose' with the same parameter types

我认为Dispose方法是由程序生成的,这就是为什么当我编写它而不生成“Dispose”时,它会给我一个错误。但是我怎样才能修复它呢

在设计器生成的文件中还有另一个
Dispose
方法。i、 e.
Painter.Designer.cs
,如果在
Dispose
中有一些自定义实现,请修改
Painter.Designer.cs
文件中的实现,或将其移到代码后面

Visual studio为每个
表单生成一个
designer.cs
文件,该文件包含关于表单上使用的控件的代码,并且还具有
Dispose
方法实现。因为您的代码隐藏有一个,所以在同一个类中有多个
Dispose
方法是一个错误。(通过
partial
关键字,两个文件具有相同的类)


如何找到designer.cs文件?我仅有的两个文件是Form1.cs和Form1.cs[Design],它们只显示我的画师表单。@muggleBlood,在解决方案资源管理器中展开表单,您将看到设计器文件。我刚刚添加了一个屏幕截图,显示了这一点。在我修改了Dispose方法后,我的程序编译时没有出现错误,但它也没有生成我想要它执行的操作。为了让代码正常工作,我所做的是从我的Form1.cs文件以及private System.Windows.Forms.Container components=null;中完全删除Dispose方法;。之后,我的程序编译没有错误并生成结果。您的表单类已经有一个Dispose()方法,存储在设计器文件中。这看起来像是.NET 1.x代码中的剪切粘贴事故,您不想使用发布的Dispose()方法。删除它就行了。