Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class always tries to open in Design View, not Code View

I have a class named Print.cs that always stubbornly opens in Design View, when I need to see its Code View (F7). It also has a different icon to the rest of my classes in the Solution Explorer.

I've looked in the Properties and can't see anything relevant. I've also tried deleting and re-creating the class, but the icon comes back.

How can I force Print.cs to always open in Code View?

(Click to enlarge)

NB: disregard the green squiggly line, it's just a warning that unreachable code was detected.

like image 720
Danny Beckett Avatar asked Mar 18 '15 14:03

Danny Beckett


4 Answers

Taken from the suggestions from @LarsTech and @OrkunBekar, since neither posted this as an answer - this works:

[System.ComponentModel.DesignerCategory("Code")]

Added between the namespace and the class, e.g.

using System;
using System.Collections.Generic;
...

namespace POS
{

    [System.ComponentModel.DesignerCategory("Code")]

    public class Print : PrintDocument
    {
        ...
    }
}
like image 199
Danny Beckett Avatar answered Oct 19 '22 10:10

Danny Beckett


Try right click on the file -> Open With -> CSharp Editor (remember to set it as default).

like image 8
kha Avatar answered Oct 19 '22 08:10

kha


Funny enough, it was totally other thing in my case. If the filename equal (=) to the first class in it, then Visual Studio decides it is a simple C# file. If you have 2 classes and the first is not equal to the file name, then the solution icon changes and default editor is designer. Visual Studio

like image 2
Ronen Avatar answered Oct 19 '22 09:10

Ronen


I don't know if you have same conditions in that link but opening your class in notepad, changing codes, replacing file then building the solution again may fix the problem.

like image 1
Orkun Bekar Avatar answered Oct 19 '22 08:10

Orkun Bekar