[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Get the screen's resolution in C#

[Get the screen's resolution in C#]

Normally a monitor displays 96 logical (or "notional") dots per inch (dpi) but it's not necessarily a good idea to assume that value. When this example starts, the following code displays the logical resolution of the screen in dpi.

private void Form1_Load(object sender, EventArgs e) { using (Graphics gr = this.CreateGraphics()) { txtScreenHorizontal.Text = gr.DpiX.ToString() + " dpi"; txtScreenVertical.Text = gr.DpiY.ToString() + " dpi"; } txtScreenHorizontal.Select(0, 0); }

The code creates a Graphics object and then uses its DpiX and DpiY properties to get the horizontal and vertical resolution.

Note that logical dots per inch is not necessarily the same as actual dots per inch on the screen. That will also depend on the screen size and the resolution that you have selected. For example, my 15" screen can use resolutions between 800 x 600 pixels and 1366 x 768 pixels but they all report 96 dpi.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.