在 Visual Studio 2008 中禁用派生类的设计器 [英] Disable Designer for a derived class in Visual Studio 2008

查看:29
本文介绍了在 Visual Studio 2008 中禁用派生类的设计器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 VS2008 设计器从 Windows.Form 类派生了 A 类.当我在 Visual Studio 解决方案资源管理器中双击文件名时,表单设计器打开.这是所需的行为.

I have class A derived from a Windows.Form class, using the VS2008 designer. When I double click on the file name in Visual Studio Solution Explorer, the form designer opens. This is the desired behavior.

我有第二个类 B,派生自 A(手动).这个类是纯代码 - 它添加了一些功能,但表单是相同的 - 但是如果我在 Visual Studio 解决方案资源管理器中双击它的文件名,它会打开表单设计器.这是不受欢迎的行为,特别是因为我需要生成类似的派生类 C-Z.

I have a second class B, derived from A (manually). This class is pure code - it adds some functionality but the form is the same - but if I double click on its file name in Visual Studio Solution Explorer, it opens the form designer. This is the undesired behavior, particularly as I will need to produce similarly derived classes C-Z.

有没有办法强制文件总是在代码编辑器中打开?我知道有两种建议的解决方法:

Is there a way of forcing the file to always open in the code editor? I'm aware of two proposed workarounds:

  1. 给 B 类属性:[System.ComponentModel.DesignerCategory("")]

  1. Give class B the attribute: [System.ComponentModel.DesignerCategory("")]

根据各种帖子,这似乎在过去有效,但在我的情况下似乎没有任何影响.VS 环境仍然会尝试为该类打开一个表单设计器.

This appears to have worked in the past according to various postings, but doesn't seem to have any effect in my situation. The VS environment still tries to open a form designer for the class.

将源文件重命名为有意义的name.Designer.cs

Rename the source file to meaningfulname.Designer.cs

这……好吧,这不太好,是吗?

This... well, it just isn't nice, is it?

解决方案 (1) 仍然有效吗?如果是这样,我可能做错了什么?

Should solution (1) still work? If so, what might I be doing wrong?

或者有其他解决方案吗?

Or is there another solution?

推荐答案

尝试使用 [System.ComponentModel.DesignerCategory("Code")] 代替.

这篇关于在 Visual Studio 2008 中禁用派生类的设计器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆