Example #1
0
        /// <summary>
        ///  Returns a TEXTMETRIC structure for the font selected in the device context
        ///  represented by this object, in units of pixels.
        /// </summary>
        public Gdi32.TEXTMETRICW GetTextMetrics()
        {
            // Set the mapping mode to MM_TEXT so we deal with units of pixels.
            Gdi32.MM mapMode = DeviceContext.MapMode;
            bool     setupDC = mapMode != Gdi32.MM.TEXT;

            if (setupDC)
            {
                // Changing the MapMode will affect viewport and window extent and origin, we save the dc
                // state so all those properties can be properly restored once done.
                DeviceContext.SaveHdc();
            }

            try
            {
                if (setupDC)
                {
                    mapMode = DeviceContext.SetMapMode(Gdi32.MM.TEXT);
                }

                var tm = new Gdi32.TEXTMETRICW();
                Gdi32.GetTextMetricsW(DeviceContext, ref tm);
                return(tm);
            }
            finally
            {
                if (setupDC)
                {
                    DeviceContext.RestoreHdc();
                }
            }
        }
Example #2
0
        /// <summary>
        ///  Returns a TEXTMETRIC structure for the font selected in the device context
        ///  represented by this object, in units of pixels.
        /// </summary>
        public IntNativeMethods.TEXTMETRIC GetTextMetrics()
        {
            IntNativeMethods.TEXTMETRIC tm = new IntNativeMethods.TEXTMETRIC();
            HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc);

            // Set the mapping mode to MM_TEXT so we deal with units of pixels.
            DeviceContextMapMode mapMode = DeviceContext.MapMode;

            bool setupDC = mapMode != DeviceContextMapMode.Text;

            if (setupDC)
            {
                // Changing the MapMode will affect viewport and window extent and origin, we save the dc
                // state so all those properties can be properly restored once done.
                DeviceContext.SaveHdc();
            }

            try
            {
                if (setupDC)
                {
                    mapMode = DeviceContext.SetMapMode(DeviceContextMapMode.Text);
                }

                IntUnsafeNativeMethods.GetTextMetrics(hdc, ref tm);
            }
            finally
            {
                if (setupDC)
                {
                    DeviceContext.RestoreHdc();
                }
            }

            return(tm);
        }
Example #3
0
            /// <devdoc>
            ///
            /// VSWhidbey #455702.
            ///
            /// Since we added mirroring to certain controls, we need to make sure the
            /// error icons show up in the correct place. We cannot mirror the errorwindow
            /// in EnsureCreated (although that would have been really easy), since we use
            /// GDI+ for some of this code, and as we all know, GDI+ does not handle mirroring
            /// at all.
            ///
            /// To work around that we create our own mirrored dc when we need to.
            ///
            /// </devdoc>
            void CreateMirrorDC(IntPtr hdc, int originOffset) {

                Debug.Assert(mirrordc == null, "Why is mirrordc non-null? Did you not call RestoreMirrorDC?");

                mirrordc = DeviceContext.FromHdc(hdc);
                if (parent.IsMirrored && mirrordc != null) {
                    mirrordc.SaveHdc();
                    mirrordcExtent = mirrordc.ViewportExtent;
                    mirrordcOrigin = mirrordc.ViewportOrigin;

                    mirrordcMode = mirrordc.SetMapMode(DeviceContextMapMode.Anisotropic);
                    mirrordc.ViewportExtent = new Size(-(mirrordcExtent.Width), mirrordcExtent.Height);
                    mirrordc.ViewportOrigin = new Point(mirrordcOrigin.X + originOffset, mirrordcOrigin.Y);
                }
            }