How Can I Find The Display Screen Dimensions Of The Used Monitor?
John K.
Bacau,

Jul 1, 2011
55 Posts

How can I find the display screen dimensions of the used monitor?

Hi! I need to build an application in which a window will have to load over the entire monitor display, containing a large chart etc. How can I dimension my form so it will load over the entire display, without affecting its components (chart, buttons positioning etc.), despite changing the monitor type and dimensions? Are there any sort of methods to find the height and width of the currently used display monitor?

Victor B.
Lake Forest, CA

Jul 1, 2011
91 Posts

Re: How can I find the display screen dimensions of the used monitor?

Hi Alex,

To find the display monitor's pixel height and width, try using the System.Windows.Forms.Screen class. Documentation is here: http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

Create an instance variable, ob of type System.Windows.Forms.Screen and use the following calls to return the Height and Width of the screen:
ob.PrimaryScreen.Bounds.Height
ob.PrimaryScreen.Bounds.Width

From there, you can place your your controls using percentages of the total screen size.

Regards,
Victor Brode

John K.
Bacau,

Jul 3, 2011
55 Posts

Re: How can I find the display screen dimensions of the used monitor?

Thanks for your reply, Victor, but I can't find the System.Windows.Forms.dll with his required header file (.h). I've found the dll only. :(. Can you please specify a link or something to get in the posession of these files?

Regards,
Alex.

Solution Available
Victor B.
Lake Forest, CA

Jul 5, 2011
91 Posts

Re: How can I find the display screen dimensions of the used monitor?

Hi Alex,

Inserting a .NET assembly is slightly different from inserting a DLL with header file.  When the Insert Library dialog window opens, select the page titled '.NET Assemblies'.  You should find an entry 'System.Windows.Forms, Version=xxxxxxx' if the assembly is registered.  Check the box next to this item and click Insert to add the library.  No header needed!

Dr. ATEasy also noted that you could use the GetSystemMetrics API included in User32.dll to get the screen size.  Since this does not require the loading of a .NET assembly, it will execute faster.  There is a sample code demonstrating usage in the example project, Language.prj. Specifically, look at test 6.1: "Calling User32 function".

Regards,
Victor Brode

John K.
Bacau,

Jul 8, 2011
55 Posts

Re: How can I find the display screen dimensions of the used monitor?

Thank you very much for your time and answer, Victor! I've managed to use the .NET Assembly. I will study the second option too. Have a nice day!


Regards,
Alex J.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]