简体   繁体   English

如何防止 Visual Studio 将文件视为组件或 forms

[英]How to keep Visual Studio from treating files as components or forms

Today I noticed that Visual Studio 2008 always treats a file as if it was a component or a form if this file contains a definition of one.今天我注意到,Visual Studio 2008 总是将文件视为组件或表单,如果该文件包含一个定义。

This means that it always opens the designer by default.这意味着它总是默认打开设计器。 I think this behavior is very annoying, because a file containing a class that derives from form or control does not have to be an actual form or control and I want to edit the source by default.我认为这种行为很烦人,因为包含源自表单或控件的 class 的文件不一定是实际的表单或控件,我想默认编辑源。

I'll just repeat the solution I found at http://social.msdn.microsoft.com/Forums/da/winformsdesigner/thread/cdfd7e6f-3ffc-4969-9ce1-c1ca0f08ae67我将重复我在http://social.msdn.microsoft.com/Forums/da/winformsdesigner/thread/cdfd7e6f-3ffc-4969-9ce1-c1ca0f08ae67找到的解决方案

Add the DesignerCategory attribute to your class like this:像这样将 DesignerCategory 属性添加到 class 中:

[System.ComponentModel.DesignerCategory("")]
public class Foo : FormDerivedClass

A class that derives from Form will always be a Form ;Form派生的 class 将始终是Form this is a fundamental concept of object orientation.这是 object 方向的基本概念。 That said, you can alter the default behavior:也就是说,您可以更改默认行为:

  • Right-click the file in question, select "Open with..." in the context menu右键单击有问题的文件 select 在上下文菜单中“打开方式...”
  • In the dialog, select "Source code (Text) editor..."在对话框中,select “源代码(文本)编辑器...”
  • Click the "Set as default" button单击“设置为默认值”按钮
  • Click OK点击确定

Right click on the file, Open With, select preferred editor from the list, Set as Default.右键单击文件,打开方式,列表中的 select 首选编辑器,设置为默认值。 Although this works for all files of that type, not for a single file.尽管这适用于该类型的所有文件,但不适用于单个文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使Visual Studio的Windows窗体设计器不会删除控件? - How do I keep Visual Studio's Windows Forms Designer from deleting controls? 如何使用GUI在Visual Studio项目中而不是直接从Visual Studio添加和编译Windows窗体? - How to add and compile windows forms in Visual Studio project using a GUI, and not directly from Visual Studio? 在Visual Studio中,如何将组件构建到最终版本中? - In Visual Studio, how to build components into final version? 使用部分类和Designer文件将Visual Studio 2003表单转换为Visual Studio 2005/2008表单 - Convert Visual Studio 2003 forms to Visual Studio 2005/2008 forms using partial classes and Designer files 有没有一种方法可以防止Visual Studio锁定在设计时设置的图像文件(即背景图像)? - Is there a way to keep Visual Studio from locking image files that you set at design time (ie, background images)? 将警告视为 Visual Studio 2019 中的错误以进行构建但不是智能感知 - Treating warnings as errors in Visual Studio 2019 for build but NOT intellisense 从 Visual Studio 备份 *.pdb 文件 - Backup *.pdb files from Visual Studio 如何在Visual Studio中使用.dll类文件? - How to use .dll class files in visual studio? 如何使用Visual Studio的控件和窗体来访问TFS版本控件 - How to use the Controls and Forms of Visual Studio to access the TFS Version Control 如何将背景图像与Windows窗体中的按钮对齐(Visual Studio) - How to align a background image with buttons in windows forms (Visual Studio)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM