c# - 禁用designer.cs中的自动更改

标签 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”。零件再次出现,这会使更多的按钮烦人。

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

最佳答案

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

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

关于c# - 禁用designer.cs中的自动更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26325975/

相关文章:

Sqlite 插入具有唯一名称,获取 id

ruby-on-rails - 如何在rails中将数据库重置回初始状态?

c# - 输入不是有效的 Base64 字符串,因为它包含非 base 64 字符

Android Studio 0.4.3 - 无法编译官方 Android 示例

c# - EF5 : LINQ to Entities does not recognize the method System. 可空系统。十进制中位数

c - 在需要浮点值的地方使用指针值

c++ - 智能感知 : cannot open source file "curl.h" in C++

javascript - 单击按钮后,在现有卡旁边自动生成一张 CSS 卡

c# - 如何只搜索 XDocument 的子项,而不是其所有后代?

C# 一个项目可以有多个 .config 文件吗?