Stop Designer from popping up on a .cs file?

  • Thread starter Michael A. Covington
  • Start date
M

Michael A. Covington

I had a lot of code in Form1.cs, so I moved some of it into another file,
Form1Op.cs, which is still a partial class of Form1 : Form.

Whenever I open Form1Op.cs, it wants to open in Form Designer rather than in
View Code. How can I change that? (Or can I?)

It compiles fine.
 
J

Jeff Johnson

I had a lot of code in Form1.cs, so I moved some of it into another file,
Form1Op.cs, which is still a partial class of Form1 : Form.

Whenever I open Form1Op.cs, it wants to open in Form Designer rather than
in View Code. How can I change that? (Or can I?)

I doubt it. Think about it. The code in Form1.cs is more than likely just
functional code, not the stuff that defines the UI (that's in
Form1.Designer.cs), but what happens when you double-click on Form1? The
designer opens. It would be kind of nice if the IDE would open the designer
only when you double-click the .Designer file and open everything else in
code mode, but I'm sure as many people would complain about that as would
enjoy it.
 
M

Mel Weaver

If you are talking about when you double click on the file name in Solution
Explorer, just right click and view code.
 
J

Jeff Johnson

If you are talking about when you double click on the file name in
Solution Explorer, just right click and view code.

Yes, of course, but I assumed the poster was talking about the "default"
action, i.e., what happens when you double-click, not that he HAD to open it
in Design view and then switch to Code view from there.
 
F

Frans Bouma [C# MVP]

Michael said:
I had a lot of code in Form1.cs, so I moved some of it into another
file, Form1Op.cs, which is still a partial class of Form1 : Form.

Whenever I open Form1Op.cs, it wants to open in Form Designer rather
than in View Code. How can I change that? (Or can I?)

It compiles fine.

Every IComponent implementing class has this behavior: it will force
vs.net to open the designer for the type of class.

You can disable this by annotating the class with an attribute. After
that, you can double click it and code is shown. Be sure to type the
full namespace in the attribute even though it's in the using blocks.
attribute to use on the class:
[System.ComponentModel.DesignerCategory("Code")]

Haven't tested it on a form, but IMHO it should work.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
J

Jeff Johnson

You can disable this by annotating the class with an attribute. After
that, you can double click it and code is shown. Be sure to type the full
namespace in the attribute even though it's in the using blocks.
attribute to use on the class:
[System.ComponentModel.DesignerCategory("Code")]

Holy crap, I'm putting this in EVERY service I've ever written right now!!
 
J

Jeff Johnson

You can disable this by annotating the class with an attribute. After
that, you can double click it and code is shown. Be sure to type the full
namespace in the attribute even though it's in the using blocks.
attribute to use on the class:
[System.ComponentModel.DesignerCategory("Code")]

Holy crap, I'm putting this in EVERY service I've ever written right now!!

Didn't work for services.
 
C

Chris Dunaway

I had a lot of code in Form1.cs, so I moved some of it into another file,
Form1Op.cs, which is still a partial class of Form1 : Form.

Whenever I open Form1Op.cs, it wants to open in Form Designer rather than in
View Code. How can I change that? (Or can I?)

It compiles fine.

Can you right click on the file in question, choose Open With....
Then select the code editor and click the "Set as Default" button.
Thereafter, when you double click the file, it should open in the code
editor.

Chris
 
J

Jeff Johnson

Can you right click on the file in question, choose Open With....
Then select the code editor and click the "Set as Default" button.
Thereafter, when you double click the file, it should open in the code
editor.

I don't know about Michael's issue, but that certainly worked for my
services!! Thanks a bunch!
 
M

Michael A. Covington

MC said:
Every IComponent implementing class has this behavior: it will force
vs.net to open the designer for the type of class.

You can disable this by annotating the class with an attribute. After
that, you can double click it and code is shown. Be sure to type the
full namespace in the attribute even though it's in the using blocks.
attribute to use on the class:
[System.ComponentModel.DesignerCategory("Code")]

Haven't tested it on a form, but IMHO it should work.

Thanks -- if it works, that's exactly what I was looking for.

It stops Designer from working on Form1 at all. I was only wanting to stop
Designer from working on one of the files that is a partial class Form1.
For now, I gave up on splitting Form1 into partial classes and moved the
code back into Form1.cs as a region.
 
M

Michael A. Covington

Chris Dunaway said:
Can you right click on the file in question, choose Open With....
Then select the code editor and click the "Set as Default" button.
Thereafter, when you double click the file, it should open in the code
editor.

*duh!* yes... that sounds like exactly what is needed. Thanks.
 
M

Michael A. Covington

Michael A. Covington said:
*duh!* yes... that sounds like exactly what is needed. Thanks.

And it isn't. Even THAT won't let me set different default behavior for 2
different files that are partial classes of the same class. Ah well...
 
J

Jeff Johnson

And it isn't. Even THAT won't let me set different default behavior for 2
different files that are partial classes of the same class. Ah well...

Yeah, I was pretty sure your situation was too specialized for that to be
the answer.
 
J

John Vottero

Michael A. Covington said:
And it isn't. Even THAT won't let me set different default behavior for 2
different files that are partial classes of the same class. Ah well...

I apologize if this has already been mentioned, I can't see the entire
thread.

Have you tried edition the project.csproj file? You should have something
like this:

<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1Op.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>

try adding "<SubType>Form</SubType>" into the Form1Op.cs Compile so you wind
up like this:

<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1Op.cs">
<SubType>Form</SubType>
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
 
J

John Vottero

MC said:
That sounds promising, but I want to say that Form1Op.cs is *not* a form
(for editing purposes), not that it is one.

In that case, say <SubType>Code</SubType>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top