日期:2014-05-17  浏览次数:20824 次

请问如何让 Form 显示在指定的 Screen 上面?
我现在的开发电脑有两个显示器,两个显示器的分辨率是一样的,一个主显示器,一个附加显示器。
Q:请问,我想让我程序 Run 起来之后,Form 显示在指定的显示器屏幕上,而这个屏幕也是 Visual Studio 所在屏幕,请问有什么好的方法?

谢谢。
显示器 分配率 指定屏幕

------解决方案--------------------
你可以问“请问如何确定Visual Studio所在的显示器?”

private void button1_Clicked(object sender, EventArgs e)
{
    var visualStudio = Process.GetProcessesByName("devenv").FirstOrDefault();
    Rectangle rect = new Rectangle();
    if (visualStudio != null && GetWindowRect(visualStudio.MainWindowHandle, ref rect))
    {
        MessageBox.Show("visual studio @" + rect);
    }
}
[DllImport("User32")]
static extern bool GetWindowRect(IntPtr hWnd, ref Rectangle rect);

当然可能有多个Visual Studio在运行,也可能一个VS跨越好几个显示器。