2007-05-31

Disable Design-Time Support in Visual Studio

I recently wrote a class in c# that inherits from System.Diagnostics.Process. This class abstracts a shelling-to-disk process that I need to do. Something like this:

public class MyShellTask : Process
{
...
}

One thing that bugged me to no end is that, in Visual Studio, when you double click the file in the Solution Explorer, it considered it "designable" even though there was no designer. So that means I got a empty page every time, telling me that it was not designable, with a link to "View Code". Well, "View Code" is what I wanted, not "View Designer", when I double-clicked!

So after getting very frustrated, I did the natural thing.. I googled looking for an answer. I had a notion that I could control this behaviour through Attribute tags on the class if only I knew the right one. Having made designable components before I was familiar with the attributes used for that. I tried fiddling about with Intellisense, Googling, all to no avail.. Nothing worked! Nothing showed up in my Google searches! Good God! What to do now?

Fiddle some more... until finally I found the right attribute:

[System.ComponentModel.DesignerCategory("")]
public class MyShellTask : Process
{
...
}


Note that you must call this with an empty string (don't believe the intellisense comment, an empty constructor call will NOT do the same as calling the constructor with an empty string.) This sets it to a non-category that it doesn't know how to deal with, and so doesn't offer designer support to you!


This also helps custom installer class for use with your Visual Studio Setup projects, which exhibit the same annoying VS UI problems... ie:

///
/// Custom Installer actions for this project.
///

[RunInstaller(true)]
[System.ComponentModel.DesignerCategory("")]
public partial class MyInstaller : Installer
{
...
}


Hope that helps someone! Now there will be at least ONE hit if someone googles up "disable design-time support" or "disable designer support" like I did!

13 comments:

Anonymous said...

Thank you SOOOO much. This has been frustrating me for weeks. I was using a Process derived class as well.

My Google search was "design class visual studios disable" and yours was the first link.

THANK YOU

Anonymous said...

Thank you for that. Works a treat.

Interestingly enough, you have to use the fully qualified name (as you say above). The following does NOT work...


using System.ComponentModel;
[DesignerCategory("")]
public MyClass...



This does

thoward37 said...

Glad I could help!

Anonymous said...

thoward37, thank you for this post. It helped me a lot.

Anonymous said...

Great stuff!!! I got the exact same search query that you described. One of those little trinkets I never seem to commit to memory: blerg. At least I know it's a google query away now :). Thanks a ton!

Anonymous said...

Thanks a lot. VS pisses me off when it tries to be too helpful.

Anonymous said...

I am poor in english, so i googled "visual studio prohibit designer support". Found this blog spot even this way. Thank you.

Anonymous said...

thanks a lot, this VS2008: "use this designer or die (tm)" was annoying endlessly.
THX

Anonymous said...

Whaou ! This works !

Thanks a lot for this trick !

I have been googling for a solution to this for months to no success.
Today, your blog entry came in first in Google with "disable the designer for a class c#".
Can you believe this ?

Thanks again !

Anonymous said...

At last! Thank you thank you thank you!

By the way, Tom, in VB.NET 2008 SP1, importing (using) works just fine:

Imports System.ComponentModel

<DesignerCategory("")> _
Class SnapForm
   Inherits System.Windows.Forms.Form
   (..)
End Class

Anonymous said...

You rock, thank you thank you thank you!!! :-)

Anonymous said...

I'm using VS 2008 SP1 and the following works for me:

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

A couple notes:

1) Contrary to the original blog post, "" does not work for me. I have to specify "Code".

2) Contrary to Anonymous, "using System.ComponentModel;" does not work for me. I have to fully qualify the namespace in the attribute for this to work. Anonymous is using VB and I'm using C#.

Anonymous said...

Most appreciated. Just what I was looking for.