TwipsPerPixel
当把VB程式转成.net 时,其座标会经常转换,用下面的程式来解决这个问题.
代码
const long HWND_DESKTOP = 0;
const int LOGPIXELSX = 88;
const int LOGPIXELSY = 90;
[DllImport("gdi32.dll ")]
private static extern int GetDeviceCaps(IntPtr hdc, int Index);
[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr Hwnd);
[DllImport("User32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
private double TwipsPerPixelX()
{
IntPtr lngDC = GetDC(IntPtr.Zero);
double perPixel= 1440 / GetDeviceCaps(lngDC, LOGPIXELSX);
ReleaseDC(IntPtr.Zero, lngDC);
return perPixel;
}
private double TwipsPerPixelY()
{
IntPtr lngDC = GetDC(IntPtr.Zero);
double perPixel = 1440 / GetDeviceCaps(lngDC, LOGPIXELSY);
ReleaseDC(IntPtr.Zero, lngDC);
return perPixel;
}
const int LOGPIXELSX = 88;
const int LOGPIXELSY = 90;
[DllImport("gdi32.dll ")]
private static extern int GetDeviceCaps(IntPtr hdc, int Index);
[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr Hwnd);
[DllImport("User32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
private double TwipsPerPixelX()
{
IntPtr lngDC = GetDC(IntPtr.Zero);
double perPixel= 1440 / GetDeviceCaps(lngDC, LOGPIXELSX);
ReleaseDC(IntPtr.Zero, lngDC);
return perPixel;
}
private double TwipsPerPixelY()
{
IntPtr lngDC = GetDC(IntPtr.Zero);
double perPixel = 1440 / GetDeviceCaps(lngDC, LOGPIXELSY);
ReleaseDC(IntPtr.Zero, lngDC);
return perPixel;
}