Beispiel #1
0
        public static _Size MeasureText(string text, Font font)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(_Size.Empty);
            }

            _Size result = _Size.DefaultFont;

            using (WindowsGraphics grf = WindowsGraphics.CreateMeasurementWindowsGraphics())
            {
                // WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(font))
                result = TextRenderer.MeasureText(grf.DeviceContext, text, font);

                // WindowsGraphicsCacheManager.MeasurementGraphics.MeasureText(text, wf);
                return(result);
            }
        }
Beispiel #2
0
        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
            {
                // 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);
                primary = ((info.dwFlags & MONITORINFOF_PRIMARY) != 0);

                deviceName = new string(info.szDevice);
                deviceName = deviceName.TrimEnd((char)0);

                if (hdc == IntPtr.Zero)
                {
                    screenDC            = UnsafeNativeMethods.CreateDC(deviceName);
                    measurementGraphics = WindowsGraphics.CreateMeasurementWindowsGraphics(screenDC);
                }
            }
            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));
            }
        }