Click here to Skip to main content
13,509,255 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 29 Aug 2010

Tips & Tricks: How to Get the Screen Resolution in Silverlight?

, 29 Aug 2010
Rate this:
Please Sign up or sign in to vote.
The code describes how to get the Client's Screen Resolution in Silverlight.

In this tips and tricks, I will show you the steps by which you can get the Screen Resolution of Client's PC in Silverlight Application. It is quite simple. You have to just call the HTML DOM object to receive the handle of the screen and from that, you can easily get the Screen Resolution.

To get the Screen Resolution, you need to get the handle of the Window and you can get it from:


Now from that object, you can call the Eval() with proper parameter "screen.width" or "screen.height" to get the Screen Width or Screen Height respectively. Those will give you the Screen Resolution. Suppose, you received Width = 1024 and Height = 768, means your Screen Resolution is: 1024 x 768.

Here is the complete code:

using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
namespace SilverlightScreenResolutionDemo
    public partial class MainPage : UserControl
        public MainPage()
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        void MainPage_Loaded(object sender, RoutedEventArgs e)
            string Width = HtmlPage.Window.Eval("screen.width").ToString();
            string Height = HtmlPage.Window.Eval("screen.height").ToString();
            MessageBox.Show(string.Format("Current resolution : {0} X {1}", Width, Height));

From the above code, you can easily understand how we are collecting the Screen Resolution of the user's screen. Hence, use it whenever you need.


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


About the Author

Kunal Chowdhury «IN»
Software Developer (Senior)
India India
Kunal Chowdhury is a Microsoft "Windows Platform Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik Developer Expert, Nokia Developer Champion, Windows 10 Champion, Microsoft Rockstar, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.

He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows Store (WinRT) app development. He posts his findings, articles, tutorials in his technical blog and CodeProject.

Book authored:

Connect with me on:

My CodeProject Awards/Prizes:

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 5 good article Pin
nikhi _singh9-Feb-12 0:57
membernikhi _singh9-Feb-12 0:57 
GeneralWarning: usually, you do <b>not</b> want to know the screen ... Pin
Pablo Aliskevicius6-Feb-12 3:13
memberPablo Aliskevicius6-Feb-12 3:13 
GeneralReason for my vote of 4 Nice and simple one Pin
Lakamraju Raghuram6-Feb-12 0:00
memberLakamraju Raghuram6-Feb-12 0:00 
GeneralReason for my vote of 3 good Pin
Vishnu Rana2-Nov-10 0:29
memberVishnu Rana2-Nov-10 0:29 
GeneralReason for my vote of 5 Thanks for sharing such cool tips Pin
Member 747486028-Sep-10 18:07
memberMember 747486028-Sep-10 18:07 
GeneralReason for my vote of 5 Thank you for sharing this tip. Pin
linuxjr29-Aug-10 7:11
memberlinuxjr29-Aug-10 7:11 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180417.1 | Last Updated 29 Aug 2010
Article Copyright 2010 by Kunal Chowdhury «IN»
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid