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.
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
{
...
}
}
Try right click on the file -> Open With
-> CSharp Editor
(remember to set it as default).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With