Visual Studio 2010 wants to open my c# class file in design mode and complains


  • 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' not found."

    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;

    namespace ABCCommon

    public class GridPrintDocAdv : GridPrintDocument
    private GridControlBase grid;
    public GridPrintDocAdv(GridControlBase grid)
    this.grid = grid;

    protected override void OnEndPrint(System.Drawing.Printing.PrintEventArgs e)
    ... etc



    Monday, October 25, 2010 5:04 PM


  • Hello,

    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.


    1. 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).
    2. If you want to go straight to code, and get rid of the designer all together, you should apply DesignerCategory attribute to your class:

    	public class GridPrintDocAdv : GridPrintDocument
    		private GridControlBase grid;
    		public GridPrintDocAdv(GridControlBase grid)
    			: base(grid)
    			this.grid = grid;
    		// ... 

    Best regards,

    • Marked as answer by Kira Qian Tuesday, November 02, 2010 8:58 AM
    Monday, October 25, 2010 8:53 PM