// This function computes everything in terms of physical size (millimeters), not pixels // private void ComputeLayout() { Debug.Assert(pageInfo != null, "Must call ComputePreview first"); layoutOk = true; if (pageInfo.Length == 0) { ClientSize = Size; return; } Graphics tempGraphics = CreateGraphicsInternal(); IntPtr dc = tempGraphics.GetHdc(); screendpi = new Point(UnsafeNativeMethods.GetDeviceCaps(new HandleRef(tempGraphics, dc), NativeMethods.LOGPIXELSX), UnsafeNativeMethods.GetDeviceCaps(new HandleRef(tempGraphics, dc), NativeMethods.LOGPIXELSY)); tempGraphics.ReleaseHdcInternal(dc); tempGraphics.Dispose(); Size pageSize = pageInfo[StartPage].PhysicalSize; Size controlPhysicalSize = new Size(PixelsToPhysical(new Point(Size), screendpi)); if (autoZoom) { double zoomX = ((double)controlPhysicalSize.Width - border * (columns + 1)) / (columns * pageSize.Width); double zoomY = ((double)controlPhysicalSize.Height - border * (rows + 1)) / (rows * pageSize.Height); zoom = Math.Min(zoomX, zoomY); } imageSize = new Size((int)(zoom * pageSize.Width), (int)(zoom * pageSize.Height)); int virtualX = (imageSize.Width * columns) + border * (columns + 1); int virtualY = (imageSize.Height * rows) + border * (rows + 1); SetVirtualSizeNoInvalidate(new Size(PhysicalToPixels(new Point(virtualX, virtualY), screendpi))); }
private static void Initialize() { if (s_isInitialized) { return; } try { string value = ConfigurationManager.AppSettings.Get(EnableHighDpiConfigurationValueName); if (string.Equals(value, "true", StringComparison.InvariantCultureIgnoreCase)) { s_enableHighDpi = true; } } catch { } if (s_enableHighDpi) { IntPtr hDC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef); if (hDC != IntPtr.Zero) { s_deviceDpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSX); s_deviceDpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSY); UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, hDC)); } } s_isInitialized = true; }
private static void Initialize() { if (isInitialized) { return; } if (IsDpiAwarenessValueSet()) { enableHighDpi = true; } else { try { // For legacy users who define this constant in app settings. But we read it only when we do not see a valid dpiawareness value in the Microsoft section string value = ConfigurationManager.AppSettings.Get(ConfigurationStringConstants.EnableWindowsFormsHighDpiAutoResizingKeyName); if (!string.IsNullOrEmpty(value) && string.Equals(value, "true", StringComparison.InvariantCultureIgnoreCase)) { enableHighDpi = true; } } catch { } } if (enableHighDpi) { #if Microsoft_NAMESPACE try { if (!DpiHelper.SetWinformsApplicationDpiAwareness()) { System.Diagnostics.Debug.WriteLine("Failed to set Application DPI awareness"); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Failed to set Application DPI awareness " + ex.ToString()); } #endif IntPtr hDC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef); if (hDC != IntPtr.Zero) { deviceDpi = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), CAPS.LOGPIXELSX); UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, hDC)); } } isInitialized = true; }
internal Screen(IntPtr monitor, IntPtr hdc) { IntPtr screenDC = hdc; if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR) { // Single monitor system // bounds = SystemInformation.VirtualScreen; workingArea = SystemInformation.WorkingArea; primary = true; deviceName = "DISPLAY"; } else { // MultiMonitor System // We call the 'A' version of GetMonitorInfoA() because // the 'W' version just never fills out the struct properly on Win2K. // NativeMethods.MONITORINFOEX info = new NativeMethods.MONITORINFOEX(); SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info); bounds = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom); workingArea = Rectangle.FromLTRB(info.rcWork.left, info.rcWork.top, info.rcWork.right, info.rcWork.bottom); primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0); int count = info.szDevice.Length; while (count > 0 && info.szDevice[count - 1] == (char)0) { count--; } deviceName = new string(info.szDevice); deviceName = deviceName.TrimEnd((char)0); if (hdc == IntPtr.Zero) { screenDC = UnsafeNativeMethods.CreateDC(deviceName); } } hmonitor = monitor; this.bitDepth = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.BITSPIXEL); this.bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.PLANES); if (hdc != screenDC) { UnsafeNativeMethods.DeleteDC(new HandleRef(null, screenDC)); } }
private static void Initialize() { if (isInitialized) { return; } IntPtr hDC = UnsafeNativeMethods.GetDC(CAPS.NullHandleRef); if (hDC != IntPtr.Zero) { deviceDpi = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), CAPS.LOGPIXELSX); UnsafeNativeMethods.ReleaseDC(CAPS.NullHandleRef, new HandleRef(null, hDC)); } isInitialized = true; }
private static void Initialize() { if (s_isInitialized) { return; } IntPtr hDC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef); if (hDC != IntPtr.Zero) { s_deviceDpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSX); s_deviceDpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSY); UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, hDC)); } s_isInitialized = true; }
private static void Initialize() { if (isInitialized) { return; } if (IsDpiAwarenessValueSet()) { enableHighDpi = true; } else { try { string text = ConfigurationManager.AppSettings.Get("EnableWindowsFormsHighDpiAutoResizing"); if (!string.IsNullOrEmpty(text) && string.Equals(text, "true", StringComparison.InvariantCultureIgnoreCase)) { enableHighDpi = true; } } catch { } } if (enableHighDpi) { try { SetWinformsApplicationDpiAwareness(); } catch (Exception) { } IntPtr dC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef); if (dC != IntPtr.Zero) { deviceDpi = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, dC), 88); UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, dC)); } } isInitialized = true; }
internal Screen(IntPtr monitor, IntPtr hdc) { IntPtr screenDC = hdc; if (!multiMonitorSupport || monitor == (IntPtr)PRIMARY_MONITOR) { // Single monitor system // bounds = SystemInformation.VirtualScreen; primary = true; deviceName = "DISPLAY"; } else { // Multiple monitor system var info = new NativeMethods.MONITORINFOEX(); SafeNativeMethods.GetMonitorInfo(new HandleRef(null, monitor), info); bounds = Rectangle.FromLTRB(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right, info.rcMonitor.bottom); primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0); deviceName = new string(info.szDevice); deviceName = deviceName.TrimEnd((char)0); if (hdc == IntPtr.Zero) { screenDC = UnsafeNativeMethods.CreateDC(deviceName); } } hmonitor = monitor; this.bitDepth = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.BITSPIXEL); this.bitDepth *= UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, screenDC), NativeMethods.PLANES); if (hdc != screenDC) { UnsafeNativeMethods.DeleteDC(new HandleRef(null, screenDC)); } }
private static void Initialize() { if (isInitialized) { return; } if (Environment.OSVersion.Platform != System.PlatformID.Win32NT) { deviceDpi = 96; // Default $$$$ } else { IntPtr hDC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef); if (hDC != IntPtr.Zero) { deviceDpi = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), CAPS.LOGPIXELSX); UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, hDC)); } } isInitialized = true; }
private static void Initialize() { if (s_isInitialized) { return; } // NOTE: In the .NET Framework, this value can be controlled via ConfigurationManager. // In .NET Core, the value always defaults to the value "true". if (s_enableHighDpi) { IntPtr hDC = UnsafeNativeMethods.GetDC(NativeMethods.NullHandleRef); if (hDC != IntPtr.Zero) { s_deviceDpiX = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSX); s_deviceDpiY = UnsafeNativeMethods.GetDeviceCaps(new HandleRef(null, hDC), SafeNativeMethods.LOGPIXELSY); UnsafeNativeMethods.ReleaseDC(NativeMethods.NullHandleRef, new HandleRef(null, hDC)); } } s_isInitialized = true; }