In case the EnumDisplaySettingsEx and ChangeDisplaySettingsEx functions do not work for you, you can also use this:
private void SetDisplayMode(DisplayMode mode)
{
var proc = new Process();
proc.StartInfo.FileName = "DisplaySwitch.exe";
switch (mode)
{
case DisplayMode.External:
proc.StartInfo.Arguments = "/external";
break;
case DisplayMode.Internal:
proc.StartInfo.Arguments = "/internal";
break;
case DisplayMode.Extend:
proc.StartInfo.Arguments = "/extend";
break;
case DisplayMode.Duplicate:
proc.StartInfo.Arguments = "/clone";
break;
}
proc.Start();
}
enum DisplayMode
{
Internal,
External,
Extend,
Duplicate
}
This will call the DisplaySwitcher with different arguments based on the required configuration. You can thus call:
SetDisplayMode(DisplayMode.Extend);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…