public Padding?GetMargins(Graphics graphics, StateTypeId state)
            {
                VisualStyleRenderer renderer = GetRenderer(state);

                if (renderer == null)
                {
                    return(null);
                }


                // VisualStyleRenderer.GetMargins always throws an exception, make an explicit API call
                int stateId = state.ToInt32(null);

                UXTheme.MARGINS margins;
                IntPtr          hdc = graphics.GetHdc();

                try
                {
                    UXTheme.GetThemeMargins(renderer.Handle, hdc, this._partId.ToInt32(null), stateId,
                                            (int)MarginProperty.SizingMargins, IntPtr.Zero, out margins);
                    // TODO: include padding
                    return(new Padding(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight));
                }
                finally
                {
                    graphics.ReleaseHdc(hdc);
                }
            }
            private VisualStyleRenderer GetRenderer(StateTypeId state)
            {
                InitRenderers();
                VisualStyleRenderer renderer;

                _renderers.TryGetValue(state, out renderer);
                return(renderer);
            }
            public void DrawText(Graphics graphics, StateTypeId state, Rectangle rect, string text)
            {
                VisualStyleRenderer r = GetRenderer(state);

                if (r != null)
                {
                    r.DrawText(graphics, rect, text); // TODO: disabled
                }
            }
            public void DrawBackground(Graphics graphics, StateTypeId state, Rectangle rect)
            {
                VisualStyleRenderer r = GetRenderer(state);

                if (r != null)
                {
                    r.DrawBackground(graphics, rect);
                }
            }
            public Size?GetPartSize(Graphics graphics, StateTypeId state)
            {
                VisualStyleRenderer renderer = GetRenderer(state);

                if (renderer == null)
                {
                    return(null);
                }

                Size size = renderer.GetPartSize(graphics, ThemeSizeType.True);

                return(size.AddHorizontally(_paddingLeft?.GetPartSize(graphics, state),
                                            _paddingRight?.GetPartSize(graphics, state)));
            }