Visual Studio Debug - 窗口开始屏幕

时间:2011-09-14 12:18:03

标签: .net winforms visual-studio-2010

有没有办法告诉Visual Studio 2010在特定屏幕上启动Windows窗体应用程序(在调试时)。

2 个答案:

答案 0 :(得分:3)

或者你可以试试这个。请注意,如果没有连接辅助屏幕,则没有错误检查。

using System;
using System.Windows.Forms;

namespace ScreenPositioning
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            #if DEBUG
            var screen = Screen.AllScreens;
            foreach (var s in screen)
            {
                if (!s.Primary)
                {
                    this.Bounds = s.Bounds;
                    this.WindowState = FormWindowState.Maximized;
                }
            }
            #endif
        }
    }
}

答案 1 :(得分:0)

更新:我在这里做了一些假设:

  1. 通过“while debugging”你的意思是“当VS调试器将被附加到进程时”,而不是“当运行调试版本时”
  2. “特定屏幕”的意思是“特定的应用程序UI”,而不是“特定的计算机显示器”(在我看到MikaelÖstberg的答案之前我甚至没有考虑过)
  3. <强>答案:

    不自动。您必须使用代码安排此操作,即设置VS以在调试时使用特定参数启动应用程序,然后将代码更改为执行以下操作:

    var mainForm = new FormToShowNormally();
    #if DEBUG
    if(debugParameterOnCommandLine) {
        mainForm = new FormToShowWhenDebugging();
    }
    #endif
    
    Application.Run(mainForm);