473,466 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Determine system's dpi setting

Can somebody please tell me how to determine the system's dpi setting (e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for custom
dpi).

Thanks,
Lance

Nov 21 '05 #1
8 9013
This is one way:

<DllImport("user32.dll")> _
Public Shared Function GetDC(ByVal hWnd As HandleRef) As IntPtr
End Function

<DllImport("gdi32.dll")> _
Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As
Integer) As Integer
End Function

<DllImport("user32.dll")> _
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr)
As Integer
End Function

dDC = GetDC(Nothing) ' Get desktop DC
dpi = GetDeviceCaps(dDC, 88)
MsgBox("DPI Value: " & dpi.ToString())
rv = ReleaseDC(Nothing, dDC)

Alternatively,

Dim dDC As IntPtr
Dim rv As Integer
Dim g As Graphics

dDC = GetDC(Nothing) 'Get desktop DC
g = Graphics.FromHdc(dDC)
MsgBox("DPI Value: " & g.DpiX.ToString())
g.Dispose()
rv = ReleaseDC(Nothing, dDC)

Yet another way, if you have a Windows form (Form1),

Dim g As Graphics

g = Graphics.FromHwnd (Form1.Handle)
MsgBox("DPI Value: " & g.DpiX.ToString())
g.Dispose()
Hope this helps?

"ljlevend2" <lj*******@nospam.nospam> wrote in message
news:5E**********************************@microsof t.com...
Can somebody please tell me how to determine the system's dpi setting (e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for
custom
dpi).

Thanks,
Lance
Nov 21 '05 #2
This is one way:

<DllImport("user32.dll")> _
Public Shared Function GetDC(ByVal hWnd As HandleRef) As IntPtr
End Function

<DllImport("gdi32.dll")> _
Public Shared Function GetDeviceCaps(ByVal hDC As IntPtr, ByVal nIndex As
Integer) As Integer
End Function

<DllImport("user32.dll")> _
Public Shared Function ReleaseDC(ByVal hWnd As IntPtr, ByVal hDC As IntPtr)
As Integer
End Function

dDC = GetDC(Nothing) ' Get desktop DC
dpi = GetDeviceCaps(dDC, 88)
MsgBox("DPI Value: " & dpi.ToString())
rv = ReleaseDC(Nothing, dDC)

Alternatively,

Dim dDC As IntPtr
Dim rv As Integer
Dim g As Graphics

dDC = GetDC(Nothing) 'Get desktop DC
g = Graphics.FromHdc(dDC)
MsgBox("DPI Value: " & g.DpiX.ToString())
g.Dispose()
rv = ReleaseDC(Nothing, dDC)

Yet another way, if you have a Windows form (Form1),

Dim g As Graphics

g = Graphics.FromHwnd (Form1.Handle)
MsgBox("DPI Value: " & g.DpiX.ToString())
g.Dispose()
Hope this helps?

"ljlevend2" <lj*******@nospam.nospam> wrote in message
news:5E**********************************@microsof t.com...
Can somebody please tell me how to determine the system's dpi setting (e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for
custom
dpi).

Thanks,
Lance
Nov 21 '05 #3
Great stuff. Thanks!

Lance

Nov 21 '05 #4
Great stuff. Thanks!

Lance

Nov 21 '05 #5
"ljlevend2" <lj*******@nospam.nospam> schrieb:
Can somebody please tell me how to determine the system's dpi setting
(e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for
custom
dpi).


Create a 'Graphics' object for a form, for example, and check its 'DpiX' and
'DpiY' properties.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6
"ljlevend2" <lj*******@nospam.nospam> schrieb:
Can somebody please tell me how to determine the system's dpi setting
(e.g.,
96 dpi for normal size, 120 dpi for large size or some other value for
custom
dpi).


Create a 'Graphics' object for a form, for example, and check its 'DpiX' and
'DpiY' properties.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
Thanks!
Lance

Nov 21 '05 #8
Thanks!
Lance

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of...
6
by: Brad | last post by:
My company is setting up a deployment process for implementing .NET Windows applications. One of the standards we want the process to enforce is verifying that the assembly is built in release...
3
by: Danny Miller | last post by:
Hi there, I've got a web app that uses impersonation and makes calls to a SQL Server backend. I'd like to be able to automate the setting of database security for the web app upon deployment....
4
by: lcifers | last post by:
Is there a way, through VB.NET, to determine if the user has selected this option? I am writing an application that does some string functions to rename files, and the file names get chopped up if...
0
by: ljlevend2 | last post by:
Can somebody please tell me how to determine the system's dpi setting (e.g., 96 dpi for normal size, 120 dpi for large size or some other value for custom dpi). Thanks, Lance
2
by: Chuck P | last post by:
How can you determine if you are in debug mode in Asp.net 2.0 I thought I could look at the web.config compilation debug directive but then I read this...
4
by: Object01 | last post by:
We're working with some benchmarks designed to test x86 vs. x64 performance (both on a x64 system). To ensure that our assemblies are loaded as x86 or x64, we specifically target our builds to the...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
I have code to bold text in a datagridviewcell: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim cs As DataGridViewCellStyle, fnt...
5
by: MLH | last post by:
Access 97 does not provide a means of reading the most recent setting for SetWarnings Method. For example, if you had CBF that called a procedure in a global module and the following statement was...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.