禁用designer.cs中的自动更改

时间:2014-10-12 14:05:42

标签: c# compiler-errors auto-generate

我在项目中创建了一个新的按钮类:

using System;
using System.Windows.Forms;

namespace CEditor
{
    public class CustomButton : Button
    {
        public CustomButton()
        {
            this.SetStyle(ControlStyles.Selectable, false);
        }
    } 
}

在表单上删除自定义按钮后,在designer.cs中生成了两行代码,每行都产生相同的错误:

namespace CEditor
{
    partial class CEditor
    {
        private CEditor.CustomButton button1;
        // Error:
        // The type name 'CustomButton' does not exist in the type 'CEditor.CEditor'

        this.button1 = new CEditor.CustomButton();
        // Error:
        // The type name 'CustomButton' does not exist in the type 'CEditor.CEditor'
    }
}

如果我删除“CEditor”,一切运行正常。两行中的部分,到目前为止都很好,但是一旦我在控件的属性面板中双击生成一个事件,设计师就“修复”上面的行,我必须删除“CEditor”。再次出现部分,这会让更多按钮变得更烦人。

我有什么办法可以阻止这种行为吗?

1 个答案:

答案 0 :(得分:0)

这就是you shouldn't give your class the same name as its namespace

的原因

更改任一名称(例如CEditorControl),您就可以了。

相关问题