How do I enable a second monitor in C#?

前端 未结 5 1000
后悔当初
后悔当初 2020-11-30 01:39

Is it possible to enable a second monitor programatically and extend the Windows Desktop onto it in C#? It needs to do the equivalent of turning on the checkbox in the image

5条回答
  •  一个人的身影
    2020-11-30 01:55

    To enable a monitor, set its position to something other than 0,0, like as shown:

    POINTL enabledPosition = new POINTL();
    enabledPosition.x = -1280;
    enabledPosition.y = 0;
    
    dm.dmPosition = enabledPosition;
    dm.dmFields = DM.Position;
    res = ChangeDisplaySettingsEx(d.DeviceName, ref dm, IntPtr.Zero, (uint) DeviceFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
    

提交回复
热议问题