我有以下代码:在C#“处置”模糊误差
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()方法,存储在设计文件中。这看起来像.NET 1.x代码中的一个剪切粘贴事故,你不希望使用你发布的Dispose()方法。只要删除它。 –