Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)
    {
        ...
    }
}
like image 547
Mircea Ispas Avatar asked Jan 14 '12 18:01

Mircea Ispas


3 Answers

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

like image 81
Haris Hasan Avatar answered Nov 16 '22 10:11

Haris Hasan


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

[System.ComponentModel.DesignerCategory("")]
like image 23
ren Avatar answered Nov 16 '22 10:11

ren


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.

like image 2
Chris Shain Avatar answered Nov 16 '22 11:11

Chris Shain