Click here to Skip to main content
11,929,655 members (57,902 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


18 bookmarked

Set Primary Display (ChangeDisplaySettingsEx)

, 11 Aug 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Simplified code for setting the primary display on a multi-monitor PC.


I've seen plenty of "complicated" code for setting the "primary" display in a multiple display PC environment, but never a "simple" C# version. (This code is based off plenty of samples I've seen on the web.)


This code originated out of the need to pop applications to multiple monitors during an automated start-up script (i.e., set a designated monitor as primary, start apps, then revert back to original monitor).

Using the code

The code is left raw for addition of "bells and whistles".

//manual gather - NewPrimary name ----------------------------------

ddOne.cb = Marshal.SizeOf(ddOne);
deviceID = 1;
WinApi.User_32.EnumDisplayDevices(null, deviceID, ref ddOne, 0);
string NewPrimary = ddOne.DeviceName;

WinApi.DEVMODE ndm6 = NewDevMode();
result = (WinApi.DisplaySetting_Results)WinApi.User_32.ChangeDisplaySettingsEx(NewPrimary, 
          ref ndm6, (IntPtr)null, (int)WinApi.DeviceFlags.CDS_SET_PRIMARY | 
          (int)WinApi.DeviceFlags.CDS_UPDATEREGISTRY, IntPtr.Zero);
Console.WriteLine("Action 3.2 result:" + result.ToString());


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Systems Engineer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

SuggestionWorking VB.Net "Conversion" Pin
LostIt127823-Jan-13 17:55
memberLostIt127823-Jan-13 17:55 
GeneralRe: Working VB.Net "Conversion" Pin
LostIt127824-Feb-13 8:59
memberLostIt127824-Feb-13 8:59 
GeneralDoes not work for me. Pin
Bill Langlais2-Nov-09 14:02
memberBill Langlais2-Nov-09 14:02 
GeneralManually set monitor\display name Pin
beyonder42211-Aug-09 6:48
memberbeyonder42211-Aug-09 6:48 
GeneralRe: Manually set monitor\display name Pin
The_Mega_ZZTer11-Aug-09 7:51
memberThe_Mega_ZZTer11-Aug-09 7:51 
GeneralRe: Manually set monitor\display name Pin
dalek925-Aug-09 3:23
memberdalek925-Aug-09 3:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 11 Aug 2009
Article Copyright 2009 by beyonder422
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid