【发布时间】: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”。又是零件,按钮越多就越烦人。
我能做些什么来阻止这种行为吗?
【问题讨论】:
-
这就是为什么你不应该给你的类赋予与其命名空间相同的名称。 blogs.msdn.com/b/ericlippert/archive/2010/03/09/…
-
你说得对,一个简单的下划线就解决了这个问题。谢谢!
标签: c# compiler-errors auto-generate