【问题标题】:disable automatic changes in designer.cs禁用 Designer.cs 中的自动更改
【发布时间】:2014-10-12 14:05:41
【问题描述】:

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

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”。又是零件,按钮越多就越烦人。

我能做些什么来阻止这种行为吗?

【问题讨论】:

标签: c# compiler-errors auto-generate


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    相关资源
    最近更新 更多