Ejemplo n.º 1
0
        public void Dispose()
        {
            // Dispose() can throw. As such we'll suppress preemptively so we don't roll right back in and
            // potentially throw again on the finalizer thread.
            SuppressFinalize();

            // We need to dispose of the WindowsGraphics if it is created by this class only, if the IDeviceContext is
            // a WindowsGraphics object we must not dispose of it since it is owned by the caller.
            if (_windowsGraphics != null && _windowsGraphics != _deviceContext)
            {
                try
                {
                    _windowsGraphics.Dispose();
                }
                finally
                {
                    // Always make an attempt to release the HDC.
                    _deviceContext?.ReleaseHdc();
                }
            }

            // Clear our fields that have finalizers
            _deviceContext   = null;
            _windowsGraphics = null;
        }
        /// <devdoc>
        ///     Dispose of cached memory dc.
        /// </devdoc>
        public static void ResetMeasurementGraphics()
        {
            if (measurementGraphics != null)
            {
#if TRACK_HDC
                //Debug.WriteLine( DbgUtil.StackTraceToStr(string.Format("Disposing measurement DC and WG for thread: [0x{0:x8}]", Thread.CurrentThread.ManagedThreadId)));
                Debug.WriteLine(DbgUtil.StackTraceToStr("Disposing measurement DC and WG"));
#endif
                measurementGraphics.Dispose();
                measurementGraphics = null;
            }
        }
Ejemplo n.º 3
0
        internal void DrawUnstretched(Graphics graphics, Rectangle targetRect)
        {
            Rectangle rectangle = targetRect;

            rectangle.X += (int)graphics.Transform.OffsetX;
            rectangle.Y += (int)graphics.Transform.OffsetY;
            WindowsGraphics graphics2 = WindowsGraphics.FromGraphics(graphics, ApplyGraphicsProperties.Clipping);
            IntPtr          hdc       = graphics2.GetHdc();

            try
            {
                this.DrawIcon(hdc, Rectangle.Empty, rectangle, false);
            }
            finally
            {
                graphics2.Dispose();
            }
        }
Ejemplo n.º 4
0
        /// <include file='doc\Icon.uex' path='docs/doc[@for="Icon.DrawUnstretched"]/*' />
        /// <devdoc>
        ///     Draws this image to a graphics object.  The drawing command originates on the graphics
        ///     object, but a graphics object generally has no idea how to render a given image.  So,
        ///     it passes the call to the actual image.  This version crops the image to the given
        ///     dimensions and allows the user to specify a rectangle within the image to draw.
        /// </devdoc>
        internal void DrawUnstretched(Graphics graphics, Rectangle targetRect)
        {
            Rectangle copy = targetRect;

            copy.X += (int)graphics.Transform.OffsetX;
            copy.Y += (int)graphics.Transform.OffsetY;

            WindowsGraphics wg = WindowsGraphics.FromGraphics(graphics, ApplyGraphicsProperties.Clipping);
            IntPtr          dc = wg.GetHdc();

            try
            {
                DrawIcon(dc, Rectangle.Empty, copy, false);
            }
            finally
            {
                wg.Dispose();
            }
        }
Ejemplo n.º 5
0
        public void Dispose(bool disposing)
        {
            Debug.Assert(disposing, "We should always dispose of this guy and not let GC do it for us!");

            if (wg != null)
            {
                // We need to dispose of the WindowsGraphics if it is created by this class only, if the IDeviceContext is
                // a WindowsGraphics object we must not dispose of it since it is owned by the caller.
                if (wg != idc)
                {
                    // resets the hdc and disposes of the internal Graphics (if inititialized from one) which releases the hdc.
                    wg.Dispose();

                    if (idc != null) // not initialized from a Graphics idc.
                    {
                        idc.ReleaseHdc();
                    }
                }

                idc = null;
                wg  = null;
            }
        }