Some time ago I had a similar problem. Didn’t found a direct function for it. After some searching on the internet, I found an answer in a formum, but don't have the link anymore.
The idea is calculating the scale from desktop resolution and screen bounds, assuming the desktop always has Hwnd =zero.
Code:
Imports System.Runtime.InteropServices
Public Class CGetScale
Private Const DESKTOPVERTRES As Integer = &H75
Private Const DESKTOPHORZRES As Integer = &H76
<DllImport("gdi32.dll")> Private Shared Function GetDeviceCaps(ByVal hdc As IntPtr, ByVal nIndex As Integer) As Integer
End Function
Public Property Xscale As Double = 1.0
Public Property Yscale As Double = 1.0
Public Sub New()
GetXYScale()
End Sub
Private Sub GetXYScale()
Using g As Graphics = Graphics.FromHwnd(IntPtr.Zero)
Dim hDc As IntPtr = g.GetHdc
Xscale = (GetDeviceCaps(hDc, DESKTOPHORZRES) / Screen.PrimaryScreen.Bounds.Width)
Yscale = (GetDeviceCaps(hDc, DESKTOPVERTRES) / Screen.PrimaryScreen.Bounds.Height)
g.ReleaseHdc(hDc)
End Using
End Sub
End Class
using the class:
Code:
Dim s As Size = Form2.PictureBox1.Size
Dim gsc As New CGetScale
s.Height = CInt(s.Height * gsc.Xscale)
s.Width = CInt(s.Width * gsc.Yscale)