Been sitting on SO for couple hours and never found the correct answer. I'm writing a windows service in C#. This service should be able to use current screen dimensions to perform calculations on them. However, every possible way of obtaining that information returns dimensions of 1024x768 (seems to be just an arbitrary minimum of some sort). The actual screen resolution is 1920x1080. I've scoured the web and used three distinct ways. No luck so far. The ways mentioned are:
- SystemInformation.MonitorSize from System.Windows.Forms
- Screen.PrimaryScreen.Bounds from System.Windows.Forms
- SystemParameters.PrimaryScreenHeight/Width from System.Windows.SystemParameters
The code snippet looks like the following:
Rectangle rect = Screen.PrimaryScreen.Bounds;
ServiceLog.WriteEntry("Screen dimensions from Screen.PrimaryScreen.Bounds: " + rect.Width + "X" + rect.Height);
Size monitorSize = SystemInformation.PrimaryMonitorSize;
int primaryScreenHeight = monitorSize.Height;
int primaryScreenWidth = monitorSize.Width;
ServiceLog.WriteEntry("Screen dimensions from Windows.Forms: " + primaryScreenWidth + "X" + primaryScreenHeight);
int screenHeight = Convert.ToInt32(SystemParameters.PrimaryScreenHeight);
int screenWidth = Convert.ToInt32(SystemParameters.PrimaryScreenWidth);
ServiceLog.WriteEntry("Got screen dimensions: " + screenWidth + "X" + screenHeight);
I am at quite a loss here and seem to have no more ideas. Can anybody help?