public IntNativeMethods.TEXTMETRIC GetTextMetrics()
        {
            IntNativeMethods.TEXTMETRIC lptm = new IntNativeMethods.TEXTMETRIC();
            HandleRef hDC  = new HandleRef(this.dc, this.dc.Hdc);
            bool      flag = this.dc.MapMode != DeviceContextMapMode.Text;

            if (flag)
            {
                this.dc.SaveHdc();
            }
            try
            {
                if (flag)
                {
                    DeviceContextMapMode mode = this.dc.SetMapMode(DeviceContextMapMode.Text);
                }
                IntUnsafeNativeMethods.GetTextMetrics(hDC, ref lptm);
            }
            finally
            {
                if (flag)
                {
                    this.dc.RestoreHdc();
                }
            }
            return(lptm);
        }
Ejemplo n.º 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 Gdi32.TEXTMETRICW GetTextMetrics()
        {
            var       tm  = new Gdi32.TEXTMETRICW();
            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);
                }

                Gdi32.GetTextMetricsW(hdc, ref tm);
            }
            finally
            {
                if (setupDC)
                {
                    DeviceContext.RestoreHdc();
                }
            }

            return(tm);
        }
Ejemplo n.º 3
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(dc, dc.Hdc);

            // Set the mapping mode to MM_TEXT so we deal with units of pixels.
            DeviceContextMapMode mapMode = dc.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.
                dc.SaveHdc();
            }

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

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

            return(tm);
        }
Ejemplo n.º 4
0
 /// <devdoc>
 ///     Sets the DC map mode and returns the old value.
 /// </devdoc>
 public DeviceContextMapMode SetMapMode(DeviceContextMapMode newMode)
 {
     return((DeviceContextMapMode)IntUnsafeNativeMethods.SetMapMode(new HandleRef(this, this.Hdc), (int)newMode));
 }
 public DeviceContextMapMode SetMapMode(DeviceContextMapMode newMode)
 {
     return (DeviceContextMapMode) IntUnsafeNativeMethods.SetMapMode(new HandleRef(this, this.Hdc), (int) newMode);
 }
Ejemplo n.º 6
0
            void RestoreMirrorDC() {
                                    
                if (parent.IsMirrored && mirrordc != null) {
                    mirrordc.ViewportExtent = mirrordcExtent;
                    mirrordc.ViewportOrigin = mirrordcOrigin;
                    mirrordc.SetMapMode(mirrordcMode);
                    mirrordc.RestoreHdc();
                    mirrordc.Dispose();
                }

                mirrordc= null;
                mirrordcExtent = Size.Empty;
                mirrordcOrigin = Point.Empty;
                mirrordcMode = DeviceContextMapMode.Text;
            }
Ejemplo n.º 7
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);
                }
            }
 private void CreateMirrorDC(IntPtr hdc, int originOffset)
 {
     this.mirrordc = DeviceContext.FromHdc(hdc);
     if (this.parent.IsMirrored && (this.mirrordc != null))
     {
         this.mirrordc.SaveHdc();
         this.mirrordcExtent = this.mirrordc.ViewportExtent;
         this.mirrordcOrigin = this.mirrordc.ViewportOrigin;
         this.mirrordcMode = this.mirrordc.SetMapMode(DeviceContextMapMode.Anisotropic);
         this.mirrordc.ViewportExtent = new Size(-this.mirrordcExtent.Width, this.mirrordcExtent.Height);
         this.mirrordc.ViewportOrigin = new Point(this.mirrordcOrigin.X + originOffset, this.mirrordcOrigin.Y);
     }
 }
 private void RestoreMirrorDC()
 {
     if (this.parent.IsMirrored && (this.mirrordc != null))
     {
         this.mirrordc.ViewportExtent = this.mirrordcExtent;
         this.mirrordc.ViewportOrigin = this.mirrordcOrigin;
         this.mirrordc.SetMapMode(this.mirrordcMode);
         this.mirrordc.RestoreHdc();
         this.mirrordc.Dispose();
     }
     this.mirrordc = null;
     this.mirrordcExtent = Size.Empty;
     this.mirrordcOrigin = Point.Empty;
     this.mirrordcMode = DeviceContextMapMode.Text;
 }