The class foo can be designed, but is not the first class in the file error

我的梦境 提交于 2020-01-01 08:46:32

问题


I have this

The class foo can be designed, but is not the first class in the file

error after adding foo class derived from TextBox in my C# file. How can I pass it, it's very annoying.

EDIT:

I want to have multiple classes in my file. I want to have some classes derived from TextBox that accept specific types of input. I'm not using the designer.

EDIT2:

class NumericTextBox : TextBox
{
    protected override void OnTextChanged(EventArgs e)
    {
        ...
    }
}

回答1:


You must have more than one classes in your file. Move your class up in the file so that it can be the first class in that file

Visual Studio requires class that was responsible for creation of file to be on top or first class of that file




回答2:


If you don't need designer altogether this class attribute should do the trick:

[System.ComponentModel.DesignerCategory("")]



回答3:


The error message is pretty clear. You have a .cs file containing multiple classes. Move each class to it's own file and you should be fine.

EDIT: If you insist on having all classes in the same file, then put the foo class at the top. Order matters- by convention, the designer uses the first class in the file for controls. You cannot have multiple control classes in the same file without seeing this error.




回答4:


Either your class.Designer.cs file OR your class.cs file will have another class defined at the top of it. Since the class is defined in both files as a partial class be sure to check both of the files!




回答5:


ALso,the name of the file must match the name of the class. For example file myClass.designer.cs expects the class myClass So check for typos.



来源:https://stackoverflow.com/questions/8864359/the-class-foo-can-be-designed-but-is-not-the-first-class-in-the-file-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!