Detect screen resolution in ASP.NET

S

simchajoy2000

Is there anyway to dynamically detect the screen resolution of a
client's computer in ASP.NET?? All the code I have found on the
internet was specifically for Access forms. I found this code:

'Module Declarations
Const WM_HORZRES = 8
Const WM_VERTRES = 10

Declare Function WM_apiGetDeviceCaps _
Lib "gdi32" Alias "GetDeviceCaps" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Declare Function WM_apiGetDesktopWindow _
Lib "user32" Alias "GetDesktopWindow" () As Long
Declare Function WM_apiGetDC _
Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function WM_apiReleaseDC _
Lib "user32" Alias "ReleaseDC" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function WM_apiGetSystemMetrics _
Lib "user32" Alias "GetSystemMetrics" _
(ByVal nIndex As Long) As Long

Function xg_GetScreenResolution() As String
'return the display height and width
Dim DisplayHeight As Integer
Dim DisplayWidth As Integer
Dim hDesktopWnd As Long
Dim hDCcaps As Long
Dim iRtn As Integer

'* make API calls to get desktop settings
hDesktopWnd = WM_apiGetDesktopWindow() 'get handle to desktop
hDCcaps = WM_apiGetDC(hDesktopWnd) 'Get Display Context
DisplayHeight = WM_apiGetDeviceCaps(hDCcaps, WM_VERTRES)
DisplayWidth = WM_apiGetDeviceCaps(hDCcaps, WM_HORZRES)
iRtn = WM_apiReleaseDC(hDesktopWnd, hDCcaps)

xg_GetScreenResolution = DisplayWidth & "x" & DisplayHeight

End Function

But whenever VB.NET gets to the DisplayHeight part, it says that "the
Arithmetic operation resulted in an overflow"

Can anyone help me either fix this problem or find another solution???
Thanks!!

Joy
 
J

Jim M

Dies this help...

screen_width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
screen_height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height

If it works, it looks easier than your solution :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top