c# - 是否可以告诉 Visual Studio 不要将源文件视为 "component"?

标签 c# visual-studio components

<分区>

Possible Duplicate:
Is there an attribute I can add to a class so it will be edited as code, not in the designer?

继承路径上带有 System.ComponentModel.Component 的类在 Visual Studio (2008) 中被自动视为“组件”,触发源文件的不同图标:

虽然图标并不重要,但更改后的双击行为确实令人讨厌:Visual Studio 现在显示一个屏幕,鼓励我将组件添加到我的类中,方法是将它们“从”工具箱”。我不想那样做!

我知道我可以右键单击源文件并选择“查看代码”,但每当我忘记这样做时,我就会一直等待一个毫无用处的对话框。有什么方法可以禁用组件行为(最好在源代码中)?

最佳答案

你不能使用 DesignerCategory 属性来装饰你的类吗?

当用如下所示的这个属性装饰你的类时,当你双击它时,文件应该在“代码 View ”中打开:

[System.ComponentModel.DesignerCategory("Code")]
public class MyComponent
{
}

关于c# - 是否可以告诉 Visual Studio 不要将源文件视为 "component"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2138684/

相关文章:

delphi - 创建不能在表单上多次添加的简单组件

javascript - 在 React 组件内循环

visual-studio - DTE.ExecuteCommand(“Edit.NextBookmark”)

c# - Resharper 说 OnPropertyChange set member can be private while not true

c# - PropertyChangedEventHandler 如何获取值?

c# - SignalR .NET 客户端在第一次连接尝试时抛出 TimeoutException

c# - VS 立即窗口 - 该名称在当前上下文中不存在

visual-studio - 优化开发虚拟机

JSF 1.2 : Can I create reusable component inside JSF view

c# - 从 Visual Studio 2015 RC 升级到 Visual Studio 2015 Community RTM 后,Blend 无法工作