I have a c# class file with one derived class. Whenever I click on the file in Solution Explorer, VS attempts to open the file in design mode and complains that it cannot find a constructor. "Warning 1 Constructor on type 'ABCCommon.GridPrintDocAdv'
I have to select "view code" to be able to edit or view the .cs code. I have no constructor for my derived class that takes no parameters because the base class has no default (i.e. parameterless) constructor. I'm used to using design mode for
winform files, but normally my c# class files open in source code view/edit mode and I don't have to continually close an extraneous designer error message/window before I can work with my code.
I created the c# class file in my project by selecting project/add/new item/c# class, so I'm a little lost as to why Visual Studio 2010 thinks it should open the file in design mode. How can I prevent this seemingly incorrect behavior in VS?
I'd appreciate any suggestions you might have. My file is as shown:
using System; using System.Collections.Generic; using System.Text; using Syncfusion.Windows.Forms.Grid; using System.Drawing; using System.Collections; using Syncfusion.GridHelperClasses; using System.IO; using System.Drawing.Printing;
it doesn't matter whether you added an item to your project as new class or new UserControl, or whatever.
The designer which is used to edit your class is inherited from the base class, so the moment you specified base class you also got the designer.
If you want the file to open in the designer you need to implement parameterless constructor (in the
GridPrintDocument class, not GridPrintDocAdv)- no other way. You can implement it just for the benefit of the design time environment, and even declare it as private so its not accessible for any other purposes
(except by reflection - which effectively breaks encapsulation concept - but that's another story).
If you want to go straight to code, and get rid of the designer all together, you should apply DesignerCategory attribute to your class: