有没有办法阻止 Visual Studio 2008 默认在设计视图中打开文件?

发布于 2024-08-17 03:07:03 字数 867 浏览 12 评论 0原文

我正在为 Windows 窗体应用程序的一部分编写 NUnit TextFixture。文件中的一些类派生自 UI 组件类,如下所示:

[TestFixture]
public class MainFormTest : PersistenceTestBase // Base class here is not a form
{
    class TestMainForm : MainForm // MainForm inherits from Form
    {
        public new String SomeMethod()
        {
            // Some MainForm private method overridden to expose it to my test fixture
        }
    }

    private TestMainForm mainForm;

    [TestFixtureSetUp]
    public void TestFixtureSetUp()
    {
        mainForm = new TestMainForm();
    }

    [Test]
    public void TestMainFormDoesXYZ()
    {
        // Perform unit testing...
    }
}

但是,我遇到的一个烦恼是,由于这些类继承自 UI 组件类,因此当我双击单元测试文件时,Windows 会打开设计器窗口在解决方案资源管理器中。其中,由于它不是“真正的”UI 元素(而是一个测试类),因此它显示为损坏的 UI(取决于我如何排列文件,诸如“无法为此文件显示设计器,因为没有类可以在其中进行设计”如图所示)。有没有办法抑制这种行为,或者我总是必须右键单击该文件并“查看代码”?

I'm writing an NUnit TextFixture for portions of a Windows Forms application. Some of the classes in the file are derived from UI component classes, like so:

[TestFixture]
public class MainFormTest : PersistenceTestBase // Base class here is not a form
{
    class TestMainForm : MainForm // MainForm inherits from Form
    {
        public new String SomeMethod()
        {
            // Some MainForm private method overridden to expose it to my test fixture
        }
    }

    private TestMainForm mainForm;

    [TestFixtureSetUp]
    public void TestFixtureSetUp()
    {
        mainForm = new TestMainForm();
    }

    [Test]
    public void TestMainFormDoesXYZ()
    {
        // Perform unit testing...
    }
}

However, an annoyance I have encountered is that since the classes inherit from UI component classes, Windows opens up the designer window when I double-click my unit test file in the Solution Explorer. Which, since it's not a "real" UI element (but a test class), it displays as a broken UI (depending on how I arrange the file, messages like "The designer could not be shown for this file because none of the classes within it can be designed" are shown). Is there a way to supress this behavior, or will I always have to right-click this file and "View Code"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

黯然#的苍凉 2024-08-24 03:07:03

右键单击,选择“打开方式...”,选择所需的编辑器,然后单击“设为默认值”。

真的需要您的测试类来假装它们不是吗?对我来说这听起来不是一个好主意。

Right click, select "Open With...", select the editor you want and click "Set as Default".

Do you really need your test classes to pretend they're something they're not though? That doesn't sound like a terribly good idea to me.

旧城烟雨 2024-08-24 03:07:03

向该类添加 [System.ComponentModel.DesignerCategory("")] 属性,以防止在解决方案资源管理器中双击文件以打开该文件时 Visual Studio 打开设计器。

Add a [System.ComponentModel.DesignerCategory("")] attribute to the class to prevent Visual Studio opening the designer when you double-click the file in Solution Explorer to open it.

旧情别恋 2024-08-24 03:07:03

另一个解决方案:

右键单击文件,然后单击打开方式...菜单。将打开一个对话框,选择Microsoft Visual Basic 编辑器,然后单击设置为默认值。单击确定即可,以后将始终使用代码编辑器而不是设计器打开该文件。

Another solution:

Right-click file and click Open With... menu. A dialog box opens, select Microsoft Visual Basic Editor and click Set as Default. Click Ok and that's it, the file will always open in the future using the code editor instead of its designer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文