The title says it all. In inches, e.g. 21' monitor. The app is a standard WinForms app.
EDIT: It appears there really isn't a reliable way to accomplish what I need. Thanks all.
The title says it all. In inches, e.g. 21' monitor. The app is a standard WinForms app.
EDIT: It appears there really isn't a reliable way to accomplish what I need. Thanks all.
If there is no .NET-specific way, you can always use the native Windows API: GetSystemMetrics
with SM_CYSCREEN
or SM_CXSCREEN
.
Web app or desktop app? All you can find out about the web app is the browser's screen resolution, using javascript:
<script language="javascript">
var width = screen.width;
var height = screen.height;
if( width < 1280 || height < 1024)
{
alert("This web page is best viewed with a screen resolution of 1280 by 1024 or higher. Your current resolution is " + width + " by " + height + ". If possible please change your resolution.");
}
else
{
alert("Your screen resolution is pretty big!")
}
</script>
For a desktop app, you do this:
MessageBox.Show( "Monitor Size:" +
SystemInformation.PrimaryMonitorSize );
This cannot be guaranteed. Windows cannot know the size of the monitor unless its driver interrogates it and reports the reply to windows.
However, you might want to try
SystemInformation.PrimaryMonitorSize
or GetDeviceCaps(dc, HORZSIZE)
and GetDeviceCaps(dc, VERTSIZE)
and then calulate the square on the hypotenuse.
Note that there is also an accepted answer to identical question right here on Stack Overflow.
I am thinking about two ways that might work under special conditions:
Try to get the name of the monitor hardware. On my dual-monitor system, I use one SyncMaster 205BW and one SyncMaster 173T. These are 20″ and 17″ monitors. You see what I mean? One problem, however, is that I am not sure if you programmatically can obtain these strings. Windows appears to only obtain SyncMaster: screenres.png.
You can use GetDeviceCaps(GetDC(GetDesktopWindow), VERTSIZE)
to obtain "Height, in millimeters, of the physical screen." and similarly with HORZSIZE
and the "width". But this will only work if you have calibrated your display, I believe. At least on my system, the values are much larger than the actual height and width...
I have no idea about your context, but if your app really does need the physical size of the end-user's output device, why not ask him? You could easily ask for the monitor's size during setup (e.g. using the excellent Inno Setup), and store the value in the registry. Then it is trivial to write a procedure GetPhysicalMonitorSize
that simply reads the value from the registry.
You may use the EDID in the registry to obtain the physical screen size. The monitor's driver reports the physical screen size to Windows.