Esempio n. 1
0
        public static void DrawText(IDeviceContext dc, string?text, Font?font, Point pt, Color foreColor, Color backColor, TextFormatFlags flags)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            Gdi32.QUALITY fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);

            using var wgr         = new WindowsGraphicsWrapper(dc, flags);
            using WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality);
            wgr.WindowsGraphics.DrawText(text, wf, pt, foreColor, backColor, GetTextFormatFlags(flags));
        }
 public void DrawBackground(IDeviceContext dc, Rectangle bounds, Rectangle clipRectangle)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (((bounds.Width >= 0) && (bounds.Height >= 0)) && ((clipRectangle.Width >= 0) && (clipRectangle.Height >= 0)))
     {
         using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
         {
             HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
             this.lastHResult = System.Windows.Forms.SafeNativeMethods.DrawThemeBackground(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(bounds), new System.Windows.Forms.NativeMethods.COMRECT(clipRectangle));
         }
     }
 }
Esempio n. 3
0
        /// <include file='doc\TextRenderer.uex' path='docs/doc[@for="TextRenderer.DrawText2"]/*' />
        public static void DrawText(IDeviceContext dc, string text, Font font, Point pt, Color foreColor, TextFormatFlags flags)
        {
            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }

            WindowsFontQuality fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);

            using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, flags))
            {
                using (WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality)) {
                    wgr.WindowsGraphics.DrawText(text, wf, pt, foreColor, GetIntTextFormatFlags(flags));
                }
            }
        }
Esempio n. 4
0
        public static void DrawText(IDeviceContext dc, string text, Font font, Rectangle bounds, Color foreColor, TextFormatFlags flags)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            Gdi32.QUALITY fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);

            using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, flags))
            {
                using (WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality))
                {
                    wgr.WindowsGraphics.DrawText(text, wf, bounds, foreColor, GetTextFormatFlags(flags));
                }
            }
        }
Esempio n. 5
0
        public static Size MeasureText(IDeviceContext dc, string?text, Font?font, Size proposedSize, TextFormatFlags flags)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }
            if (string.IsNullOrEmpty(text))
            {
                return(Size.Empty);
            }

            Gdi32.QUALITY fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);

            using var wgr = new WindowsGraphicsWrapper(dc, flags);
            using var wf  = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality);
            return(wgr.WindowsGraphics.MeasureText(text, wf, proposedSize, GetTextFormatFlags(flags)));
        }
Esempio n. 6
0
        public static Size MeasureText(IDeviceContext dc, string text, Font font, Size proposedSize, TextFormatFlags flags)
        {
            Size size;

            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }
            if (string.IsNullOrEmpty(text))
            {
                return(Size.Empty);
            }
            WindowsFontQuality fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);

            using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, flags))
            {
                using (WindowsFont font2 = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality))
                {
                    size = wrapper.WindowsGraphics.MeasureText(text, font2, proposedSize, GetIntTextFormatFlags(flags));
                }
            }
            return(size);
        }
Esempio n. 7
0
        private static Size MeasureTextInternal(
            IDeviceContext dc,
            string?text,
            Font?font,
            Size proposedSize,
            TextFormatFlags flags = TextFormatFlags.Bottom)
        {
            if (dc == null)
            {
                throw new ArgumentNullException(nameof(dc));
            }

            if (string.IsNullOrEmpty(text))
            {
                return(Size.Empty);
            }

            // This MUST come before retreiving the HDC, which locks the Graphics object
            Gdi32.QUALITY quality = FontQualityFromTextRenderingHint(dc);

            using var wgr = new WindowsGraphicsWrapper(dc, flags);
            using var wf  = WindowsGraphicsCacheManager.GetWindowsFont(font, quality);
            return(wgr.WindowsGraphics.MeasureText(text, wf, proposedSize, GetTextFormatFlags(flags)));
        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.DrawText2"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public void DrawText(IDeviceContext dc, Rectangle bounds, string textToDraw, bool drawDisabled, TextFormatFlags flags) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }

            if (bounds.Width < 0 || bounds.Height < 0) {
                return;
            }
            
            int disableFlag = drawDisabled?0x1:0;
            
            if (!String.IsNullOrEmpty(textToDraw)) {
                using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                    HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                    lastHResult = SafeNativeMethods.DrawThemeText( new HandleRef( this, Handle ), hdc, part, state, textToDraw, textToDraw.Length, (int) flags, disableFlag, new NativeMethods.COMRECT( bounds ) );
                }
            }
        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetBackgroundExtent"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public Rectangle GetBackgroundExtent(IDeviceContext dc, Rectangle contentBounds) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            if (contentBounds.Width < 0 || contentBounds.Height < 0) {
                return Rectangle.Empty;
            }
            
            NativeMethods.COMRECT rect = new NativeMethods.COMRECT();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemeBackgroundExtent( new HandleRef( this, Handle ), hdc, part, state, new NativeMethods.COMRECT( contentBounds ), rect );
            }

            return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);
        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.DrawEdge"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public Rectangle DrawEdge(IDeviceContext dc, Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects) {
            if (dc == null) {
                throw new ArgumentNullException("dc");
            }

            if (!ClientUtils.IsEnumValid_Masked(edges, (int)edges,(UInt32)(Edges.Left | Edges.Top | Edges.Right | Edges.Bottom | Edges.Diagonal))) {
                throw new InvalidEnumArgumentException("edges", (int)edges, typeof(Edges));
            }

            if (!ClientUtils.IsEnumValid_NotSequential(style, (int)style, (int)EdgeStyle.Raised,(int)EdgeStyle.Sunken,(int)EdgeStyle.Etched,(int)EdgeStyle.Bump )) {
                throw new InvalidEnumArgumentException("style", (int)style, typeof(EdgeStyle));
            }

            if (!ClientUtils.IsEnumValid_Masked(effects, (int)effects, (UInt32)(EdgeEffects.FillInterior | EdgeEffects.Flat | EdgeEffects.Soft | EdgeEffects.Mono))) {
                throw new InvalidEnumArgumentException("effects", (int)effects, typeof(EdgeEffects));
            }

            NativeMethods.COMRECT rect = new NativeMethods.COMRECT();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.DrawThemeEdge( new HandleRef( this, Handle ), hdc, part, state, new NativeMethods.COMRECT( bounds ), (int) style, (int) edges | (int) effects | EdgeAdjust, rect );
            }

            return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);
        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.DrawParentBackground"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Given a graphics object and bounds to draw in, this method effectively asks the passed in 
        ///       control's parent to draw itself in there (it sends WM_ERASEBKGND & WM_PRINTCLIENT messages
        ///       to the parent).
        ///    </para>
        /// </devdoc>
        public void DrawParentBackground(IDeviceContext dc, Rectangle bounds, Control childControl) {
            if (dc == null) {
                throw new ArgumentNullException("dc");
            }

            if (childControl == null) {
                throw new ArgumentNullException("childControl");
            }

            if (bounds.Width < 0 || bounds.Height < 0) {
                return;
            }

            if (childControl.Handle != IntPtr.Zero) {
                using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                    HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                    lastHResult = SafeNativeMethods.DrawThemeParentBackground( new HandleRef( this, childControl.Handle ), hdc, new NativeMethods.COMRECT( bounds ) );
                }
            }
        }
 public Region GetBackgroundRegion(IDeviceContext dc, Rectangle bounds)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if ((bounds.Width < 0) || (bounds.Height < 0))
     {
         return null;
     }
     IntPtr zero = IntPtr.Zero;
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemeBackgroundRegion(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(bounds), ref zero);
     }
     if (zero == IntPtr.Zero)
     {
         return null;
     }
     Region region = Region.FromHrgn(zero);
     System.Windows.Forms.SafeNativeMethods.ExternalDeleteObject(new HandleRef(null, zero));
     return region;
 }
 public void DrawText(IDeviceContext dc, Rectangle bounds, string textToDraw, bool drawDisabled, TextFormatFlags flags)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if ((bounds.Width >= 0) && (bounds.Height >= 0))
     {
         int num = drawDisabled ? 1 : 0;
         if (!string.IsNullOrEmpty(textToDraw))
         {
             using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
             {
                 HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
                 this.lastHResult = System.Windows.Forms.SafeNativeMethods.DrawThemeText(new HandleRef(this, this.Handle), hdc, this.part, this.state, textToDraw, textToDraw.Length, (int) flags, num, new System.Windows.Forms.NativeMethods.COMRECT(bounds));
             }
         }
     }
 }
 public HitTestCode HitTestBackground(IDeviceContext dc, Rectangle backgroundRectangle, IntPtr hRgn, Point pt, HitTestOptions options)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     int pwHitTestCode = 0;
     System.Windows.Forms.NativeMethods.POINTSTRUCT ptTest = new System.Windows.Forms.NativeMethods.POINTSTRUCT(pt.X, pt.Y);
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.HitTestThemeBackground(new HandleRef(this, this.Handle), hdc, this.part, this.state, (int) options, new System.Windows.Forms.NativeMethods.COMRECT(backgroundRectangle), new HandleRef(this, hRgn), ptTest, ref pwHitTestCode);
     }
     return (HitTestCode) pwHitTestCode;
 }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetPartSize1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public Size GetPartSize(IDeviceContext dc, Rectangle bounds, ThemeSizeType type) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            
            //valid values are 0x0 to 0x2
            if (!ClientUtils.IsEnumValid(type, (int)type, (int)ThemeSizeType.Minimum, (int)ThemeSizeType.Draw))
            {
                throw new InvalidEnumArgumentException("type", (int)type, typeof(ThemeSizeType));
            }

            NativeMethods.SIZE size = new NativeMethods.SIZE();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemePartSize( new HandleRef( this, Handle ), hdc, part, state, new NativeMethods.COMRECT( bounds ), type, size );
            }

            return new Size(size.cx, size.cy);
        } 
 public Rectangle GetTextExtent(IDeviceContext dc, Rectangle bounds, string textToDraw, TextFormatFlags flags)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (string.IsNullOrEmpty(textToDraw))
     {
         throw new ArgumentNullException("textToDraw");
     }
     System.Windows.Forms.NativeMethods.COMRECT pExtentRect = new System.Windows.Forms.NativeMethods.COMRECT();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemeTextExtent(new HandleRef(this, this.Handle), hdc, this.part, this.state, textToDraw, textToDraw.Length, (int) flags, new System.Windows.Forms.NativeMethods.COMRECT(bounds), pExtentRect);
     }
     return Rectangle.FromLTRB(pExtentRect.left, pExtentRect.top, pExtentRect.right, pExtentRect.bottom);
 }
 public TextMetrics GetTextMetrics(IDeviceContext dc)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     TextMetrics ptm = new TextMetrics();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemeTextMetrics(new HandleRef(this, this.Handle), hdc, this.part, this.state, ref ptm);
     }
     return ptm;
 }
 public Size GetPartSize(IDeviceContext dc, Rectangle bounds, ThemeSizeType type)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (!System.Windows.Forms.ClientUtils.IsEnumValid(type, (int) type, 0, 2))
     {
         throw new InvalidEnumArgumentException("type", (int) type, typeof(ThemeSizeType));
     }
     System.Windows.Forms.NativeMethods.SIZE psz = new System.Windows.Forms.NativeMethods.SIZE();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemePartSize(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(bounds), type, psz);
     }
     return new Size(psz.cx, psz.cy);
 }
 public Padding GetMargins(IDeviceContext dc, MarginProperty prop)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (!System.Windows.Forms.ClientUtils.IsEnumValid(prop, (int) prop, 0xe11, 0xe13))
     {
         throw new InvalidEnumArgumentException("prop", (int) prop, typeof(MarginProperty));
     }
     System.Windows.Forms.NativeMethods.MARGINS margins = new System.Windows.Forms.NativeMethods.MARGINS();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hDC = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemeMargins(new HandleRef(this, this.Handle), hDC, this.part, this.state, (int) prop, ref margins);
     }
     return new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
 }
 public Font GetFont(IDeviceContext dc, FontProperty prop)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (!System.Windows.Forms.ClientUtils.IsEnumValid(prop, (int) prop, 0xa29, 0xa29))
     {
         throw new InvalidEnumArgumentException("prop", (int) prop, typeof(FontProperty));
     }
     System.Windows.Forms.NativeMethods.LOGFONT pFont = new System.Windows.Forms.NativeMethods.LOGFONT();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemeFont(new HandleRef(this, this.Handle), hdc, this.part, this.state, (int) prop, pFont);
     }
     Font font = null;
     if (!System.Windows.Forms.NativeMethods.Succeeded(this.lastHResult))
     {
         return font;
     }
     System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
     try
     {
         return Font.FromLogFont(pFont);
     }
     catch (Exception exception)
     {
         if (System.Windows.Forms.ClientUtils.IsSecurityOrCriticalException(exception))
         {
             throw;
         }
         return null;
     }
 }
        public Region GetBackgroundRegion(IDeviceContext dc, Rectangle bounds) {
            if (dc == null) {
                throw new ArgumentNullException("dc");
            }
            if (bounds.Width < 0 || bounds.Height < 0) {
                return null;
            }

            IntPtr hRegion = IntPtr.Zero;

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemeBackgroundRegion( new HandleRef( this, Handle ), hdc, part, state, new NativeMethods.COMRECT( bounds ), ref hRegion );
            }

            // GetThemeBackgroundRegion returns a null hRegion if it fails to create one, it could be because the bounding
            // box is too big. For more info see code in %xpsrc%\shell\themes\uxtheme\imagefile.cpp if you have an enlistment to it.

		if (hRegion == IntPtr.Zero) {
			return null;
		}

		// From the GDI+ sources it doesn't appear as if they take ownership of the hRegion, so this is safe to do.
		// We need to DeleteObject in order to not leak. DevDiv Bugs 169791
		Region region = Region.FromHrgn(hRegion);
		SafeNativeMethods.ExternalDeleteObject(new HandleRef(null, hRegion));
		return region;

        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetTextExtent1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public Rectangle GetTextExtent(IDeviceContext dc, Rectangle bounds, string textToDraw, TextFormatFlags flags) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            
            if (String.IsNullOrEmpty(textToDraw)) {
                throw new ArgumentNullException("textToDraw");
            }

            NativeMethods.COMRECT rect = new NativeMethods.COMRECT();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemeTextExtent( new HandleRef( this, Handle ), hdc, part, state, textToDraw, textToDraw.Length, (int) flags, new NativeMethods.COMRECT( bounds ), rect );
            }

            return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);
        }
        public Font GetFont(IDeviceContext dc, FontProperty prop)
        {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            
            //valid values are 0xa29 to 0xa29
            if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)FontProperty.GlyphFont, (int)FontProperty.GlyphFont))
            {
                throw new InvalidEnumArgumentException("prop", (int)prop, typeof(FontProperty));
            }

            NativeMethods.LOGFONT logfont = new NativeMethods.LOGFONT();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemeFont( new HandleRef( this, Handle ), hdc, part, state, (int) prop, logfont );
            }

            Font font = null;

            //check for a failed HR.
            if (NativeMethods.Succeeded(lastHResult)) {


                // SECREVIEW: Safe to assert here, since the logfont comes from a native api and not from the 
                //            caller of this method.  The system creates the font handle.
                //
                IntSecurity.ObjectFromWin32Handle.Assert();
                try {
                    font = Font.FromLogFont(logfont);
                }
                catch (Exception e) {
                    if (ClientUtils.IsSecurityOrCriticalException(e)) {
                        throw;
                    }

                    //Looks like the font was not true type
                    font = null;
                }
            }

            return font;
        }
        public HitTestCode HitTestBackground(IDeviceContext dc, Rectangle backgroundRectangle, IntPtr hRgn, Point pt, HitTestOptions options) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            
            int htCode = 0;
            NativeMethods.POINTSTRUCT point = new NativeMethods.POINTSTRUCT(pt.X, pt.Y);

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.HitTestThemeBackground( new HandleRef( this, Handle ), hdc, part, state, (int) options, new NativeMethods.COMRECT( backgroundRectangle ), new HandleRef( this, hRgn ), point, ref htCode );
            }

            return (HitTestCode)htCode;
        }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetMargins"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public Padding GetMargins(IDeviceContext dc, MarginProperty prop) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            
            //valid values are 0xe11 to 0xe13
            if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)MarginProperty.SizingMargins, (int)MarginProperty.CaptionMargins))
            {
                throw new InvalidEnumArgumentException("prop", (int)prop, typeof(MarginProperty));
            }

            NativeMethods.MARGINS margins = new NativeMethods.MARGINS();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemeMargins( new HandleRef( this, Handle ), hdc, part, state, (int) prop, ref margins );
            }

            return new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight);
        }
 public Rectangle GetBackgroundExtent(IDeviceContext dc, Rectangle contentBounds)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if ((contentBounds.Width < 0) || (contentBounds.Height < 0))
     {
         return Rectangle.Empty;
     }
     System.Windows.Forms.NativeMethods.COMRECT pExtentRect = new System.Windows.Forms.NativeMethods.COMRECT();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.GetThemeBackgroundExtent(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(contentBounds), pExtentRect);
     }
     return Rectangle.FromLTRB(pExtentRect.left, pExtentRect.top, pExtentRect.right, pExtentRect.bottom);
 }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.GetTextMetric"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public TextMetrics GetTextMetrics(IDeviceContext dc) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            
            TextMetrics tm = new TextMetrics();

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.GetThemeTextMetrics( new HandleRef( this, Handle ), hdc, part, state, ref tm );
            }

            return tm;
        }
 public static void DrawText(IDeviceContext dc, string text, Font font, Point pt, Color foreColor, TextFormatFlags flags)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     WindowsFontQuality fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, flags))
     {
         using (WindowsFont font2 = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality))
         {
             wrapper.WindowsGraphics.DrawText(text, font2, pt, foreColor, GetIntTextFormatFlags(flags));
         }
     }
 }
        /// <include file='doc\VisualStyleRenderer.uex' path='docs/doc[@for="VisualStyleRenderer.DrawBackground1"]/*' />
        /// <devdoc>
        ///    <para>
        ///       [See win32 equivalent.]
        ///    </para>
        /// </devdoc>
        public void DrawBackground(IDeviceContext dc, Rectangle bounds, Rectangle clipRectangle) {
            if( dc == null ){
                throw new ArgumentNullException("dc");
            }
            if (bounds.Width < 0 || bounds.Height < 0) {
                return;
            }
            if (clipRectangle.Width < 0 || clipRectangle.Height < 0) {
                return;
            }

            using( WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper( dc, AllGraphicsProperties ) ) {
                HandleRef hdc = new HandleRef( wgr, wgr.WindowsGraphics.DeviceContext.Hdc );
                lastHResult = SafeNativeMethods.DrawThemeBackground( new HandleRef( this, Handle ), hdc, part, state, new NativeMethods.COMRECT( bounds ), new NativeMethods.COMRECT( clipRectangle ) );
            }
        }
 public void DrawParentBackground(IDeviceContext dc, Rectangle bounds, Control childControl)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (childControl == null)
     {
         throw new ArgumentNullException("childControl");
     }
     if (((bounds.Width >= 0) && (bounds.Height >= 0)) && (childControl.Handle != IntPtr.Zero))
     {
         using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
         {
             HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
             this.lastHResult = System.Windows.Forms.SafeNativeMethods.DrawThemeParentBackground(new HandleRef(this, childControl.Handle), hdc, new System.Windows.Forms.NativeMethods.COMRECT(bounds));
         }
     }
 }
 public Rectangle DrawEdge(IDeviceContext dc, Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects)
 {
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (!System.Windows.Forms.ClientUtils.IsEnumValid_Masked(edges, (int) edges, 0x1f))
     {
         throw new InvalidEnumArgumentException("edges", (int) edges, typeof(Edges));
     }
     if (!System.Windows.Forms.ClientUtils.IsEnumValid_NotSequential(style, (int) style, new int[] { 5, 10, 6, 9 }))
     {
         throw new InvalidEnumArgumentException("style", (int) style, typeof(EdgeStyle));
     }
     if (!System.Windows.Forms.ClientUtils.IsEnumValid_Masked(effects, (int) effects, 0xd800))
     {
         throw new InvalidEnumArgumentException("effects", (int) effects, typeof(EdgeEffects));
     }
     System.Windows.Forms.NativeMethods.COMRECT pContentRect = new System.Windows.Forms.NativeMethods.COMRECT();
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping))
     {
         HandleRef hdc = new HandleRef(wrapper, wrapper.WindowsGraphics.DeviceContext.Hdc);
         this.lastHResult = System.Windows.Forms.SafeNativeMethods.DrawThemeEdge(new HandleRef(this, this.Handle), hdc, this.part, this.state, new System.Windows.Forms.NativeMethods.COMRECT(bounds), (int) style, ((int) (edges | ((Edges) ((int) effects)))) | 0x2000, pContentRect);
     }
     return Rectangle.FromLTRB(pContentRect.left, pContentRect.top, pContentRect.right, pContentRect.bottom);
 }
 public static Size MeasureText(IDeviceContext dc, string text, Font font, Size proposedSize, TextFormatFlags flags)
 {
     Size size;
     if (dc == null)
     {
         throw new ArgumentNullException("dc");
     }
     if (string.IsNullOrEmpty(text))
     {
         return Size.Empty;
     }
     WindowsFontQuality fontQuality = WindowsFont.WindowsFontQualityFromTextRenderingHint(dc as Graphics);
     using (WindowsGraphicsWrapper wrapper = new WindowsGraphicsWrapper(dc, flags))
     {
         using (WindowsFont font2 = WindowsGraphicsCacheManager.GetWindowsFont(font, fontQuality))
         {
             size = wrapper.WindowsGraphics.MeasureText(text, font2, proposedSize, GetIntTextFormatFlags(flags));
         }
     }
     return size;
 }