public static double MillimetersToPixelsWidth(double length) //length是毫米,1厘米=10毫米
{
System.Windows.Forms.Panel p = new System.Windows.Forms.Panel();
System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(p.Handle);
TextBox txt = new TextBox();
IntPtr hdc = g.GetHdc();
int width = GetDeviceCaps(hdc, 4); // HORZRES
int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL
g.ReleaseHdc(hdc);
return (((double)pixels / (double)width) * (double)length);
}
[DllImport("gdi32.dll")]
private static extern int GetDeviceCaps(IntPtr hdc, int Index);
时间: 2024-12-20 03:50:01