public void Paint(BidiGraphics g)
        {
            foreach ( LinkCommand linkCommand in _contentSourceCommands )
                linkCommand.Paint(g);

            if (MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.WLGallery))
            {
                int y = _addPluginCommand.Bounds.Y - ADD_PLUGIN_PAD ;
                using ( Pen pen = PanelBody.CreateBorderPen() )
                    g.DrawLine(pen, _addPluginCommand.Bounds.X, y, _parent.Right - _addPluginCommand.Bounds.X, y);

                _addPluginCommand.Paint(g);
            }
        }
        public void Paint(BidiGraphics g)
        {
            ColorizedResources colRes = ColorizedResources.Instance;

            if(!ColorizedResources.UseSystemColors)
            {
                using (Brush b = new SolidBrush(Color.FromArgb(64, Color.White)))
                    g.FillRectangle(b, Bounds );

                using (Pen p = CreateBorderPen())
                {
                    g.DrawLine(p, Bounds.Left, Bounds.Top, Bounds.Left, Bounds.Bottom - 1); // left
                    g.DrawLine(p, Bounds.Right, Bounds.Top, Bounds.Right, Bounds.Bottom - 1); // left
                    g.DrawLine(p, Bounds.Left + 1, Bounds.Bottom, Bounds.Right - 1, Bounds.Bottom);
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {

            base.OnPaint(e);
            BidiGraphics g = new BidiGraphics(e.Graphics, VirtualClientRectangle);

            Rectangle tabRectangle = VirtualClientRectangle;

            if (selected)
                ColorizedResources.Instance.ViewSwitchingTabSelected.DrawBorder(e.Graphics, tabRectangle);
            else
                ColorizedResources.Instance.ViewSwitchingTabUnselected.DrawBorder(e.Graphics, tabRectangle);

            if (ColorizedResources.UseSystemColors)
            {
                if (BorderColor.HasValue)
                {
                    using (Pen pen = new Pen(BorderColor.Value))
                    {
                        if (!selected)
                            g.DrawLine(pen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Right,
                                       tabRectangle.Top);
                        g.DrawLine(pen, tabRectangle.Left, tabRectangle.Top, tabRectangle.Left,
                                   tabRectangle.Bottom);
                        g.DrawLine(pen, tabRectangle.Right - 1, tabRectangle.Top, tabRectangle.Right - 1,
                                   tabRectangle.Bottom);
                        g.DrawLine(pen, tabRectangle.Left, tabRectangle.Bottom - 1,
                                   tabRectangle.Right, tabRectangle.Bottom - 1);
                    }
                }
            }

            /*
            if (!selected && !SystemInformation.HighContrast)
            {

                using (Pen p = new Pen(borderColor, 1.0f))
                    g.DrawLine(p, 0, 0, VirtualWidth, 0);
                using (Pen p = new Pen(Color.FromArgb(192, borderColor), 1.0f))
                    g.DrawLine(p, 0, 1, VirtualWidth - 1, 1);
                using (Pen p = new Pen(Color.FromArgb(128, borderColor), 1.0f))
                    g.DrawLine(p, 0, 2, VirtualWidth - 2, 2);
                using (Pen p = new Pen(Color.FromArgb(64, borderColor), 1.0f))
                    g.DrawLine(p, 0, 3, VirtualWidth - 2, 3);
            }
             * */

            Rectangle textBounds = tabRectangle;
            if (!selected)
                textBounds.Y += (int)DisplayHelper.ScaleX(3);
            else
                textBounds.Y += (int)DisplayHelper.ScaleX(3);

            Color textColor = ColorizedResources.Instance.MainMenuTextColor;
            if (selected)
                textColor = Parent.ForeColor;

            g.DrawText(Text, selected ? ctx.Font : ctx.Font, textBounds, SystemInformation.HighContrast ? SystemColors.ControlText : textColor,
                       TextFormatFlags.Top | TextFormatFlags.HorizontalCenter | TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.PreserveGraphicsClipping);
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get video we are rendering
            IVideo video = Items[e.Index] as IVideo;

            // determine state
            bool selected = ((e.State & DrawItemState.Selected) > 0) && !_preventSelectionPainting;

            // calculate colors
            Color textColor;
            if (selected)
            {
                if (Focused)
                {
                    textColor = SystemColors.HighlightText;
                }
                else
                {
                    textColor = SystemColors.ControlText;
                }
            }
            else
            {
                textColor = SystemColors.ControlText;
            }
            Color previewColor = Color.FromArgb(200, textColor);

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;

            // draw background
            e.DrawBackground();
            //using (SolidBrush solidBrush = new SolidBrush(backColor))
            //    g.FillRectangle(solidBrush, e.Bounds);

            // draw the thumbnail image
            Rectangle thumbnailRect = new Rectangle(e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(VERTICAL_INSET), THUMBNAIL_IMAGE_WIDTH, THUMBNAIL_IMAGE_HEIGHT);
            VideoThumbnail thumbnail = _thumbnailManager.GetThumbnail(video);
            thumbnail.Draw(g, e.Font, thumbnailRect);

            // calculate standard text drawing metrics
            int leftMargin = ScaleX(HORIZONTAL_INSET) + THUMBNAIL_IMAGE_WIDTH + ScaleX(HORIZONTAL_INSET);
            int topMargin = e.Bounds.Top + ScaleY(VERTICAL_INSET);
            int fontHeight = g.MeasureText(video.Title, e.Font).Height;

            // draw title and duration
            int titleWidth;
            Rectangle durationRectangle;
            using (Font hyperlinkFont = new Font(e.Font, FontStyle.Underline))
            {
                titleWidth = e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - leftMargin;
                Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight);

                string title = video.Title ?? "";

                g.DrawText(title,
                    hyperlinkFont,
                    titleRectangle, selected ? textColor : SystemColors.HotTrack, ellipsesStringFormat);
            }

            using (Font durationFont = new Font(e.Font, FontStyle.Regular)) // was bold
            {
                durationRectangle = new Rectangle(leftMargin, topMargin + fontHeight + 3, titleWidth, fontHeight);

                string duration = String.Format(CultureInfo.InvariantCulture, "{0:00}:{1:00}", video.LengthSeconds / 60, video.LengthSeconds % 60);

                g.DrawText(
                    duration,
                    durationFont,
                    durationRectangle, textColor, ellipsesStringFormat);
            }

            // draw description

            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                leftMargin,
                durationRectangle.Bottom + ScaleY(VERTICAL_INSET),
                e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET),
                e.Bounds.Bottom - ScaleY(VERTICAL_INSET) - durationRectangle.Bottom - ScaleY(VERTICAL_INSET));

            // draw description
            g.DrawText(
                video.Description,
                e.Font, layoutRectangle, previewColor, ellipsesStringFormat);

            // draw bottom-line if necessary
            if (!selected)
            {
                using (Pen pen = new Pen(SystemColors.ControlLight))
                    g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - ScaleY(1), e.Bounds.Right, e.Bounds.Bottom - ScaleY(1));
            }

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            BidiGraphics g = new BidiGraphics(e.Graphics, _controlRectangle);

            Color backgroundColor = ColorizedResources.Instance.SidebarGradientBottomColor;
            using (Brush brush = new SolidBrush(backgroundColor))
                g.FillRectangle(brush, _controlRectangle);

            if (!(_image == null && (Text == null || Text == string.Empty)))
            {
                // draw the border
                using (Pen pen = new Pen(ColorizedResources.Instance.BorderLightColor))
                {
                    g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Top, _controlRectangle.Width, _controlRectangle.Top);
                    g.DrawLine(pen, _controlRectangle.Left, _controlRectangle.Bottom, _controlRectangle.Width, _controlRectangle.Bottom);
                }

                // draw the image
                if (_image != null)
                    g.DrawImage(true, _image, new Rectangle(_imageRectangle.Left, _imageRectangle.Top, _image.Width, _image.Height));

                // draw the text
                g.DrawText(Text, ApplicationManager.ApplicationStyle.NormalApplicationFont,
                                       new Rectangle(_textRectangle.X, _textRectangle.Y, _textRectangle.Width, _textRectangle.Height),
                                       ApplicationManager.ApplicationStyle.PrimaryWorkspaceCommandBarTextColor,
                                       _stringFormat);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.ResetClip();
            BidiGraphics g = new BidiGraphics(e.Graphics, Bounds, false);

            using (Brush brush = new SolidBrush(SystemColors.ActiveCaption))
            {
                g.FillRectangle(brush, new Rectangle(0, 0, Width - 1, SystemInformation.ToolWindowCaptionHeight));
            }

            using (Pen borderPen = new Pen(Color.FromArgb(127, 157, 185)))
            {
                g.DrawRectangle(borderPen, new Rectangle(0, 0, Width - 1, Height - 1));
                g.DrawLine(borderPen, 0, SystemInformation.ToolWindowCaptionHeight, Width - 1, SystemInformation.ToolWindowCaptionHeight);
            }

            using (Font boldFont = new Font(Font, FontStyle.Bold))
                g.DrawText(Text, boldFont, new Rectangle(4, 2, Width - 2, SystemInformation.ToolWindowCaptionHeight - 1), SystemColors.ActiveCaptionText);

        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get post we are rendering
            PostInfo postInfo = (Items[e.Index] as PostInfoItem).PostInfo;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;
            if (selected)
            {
                if (Focused)
                {
                    backColor = _theme.backColorSelectedFocused;
                    textColor = _theme.textColorSelectedFocused;
                }
                else
                {
                    backColor = _theme.backColorSelected;
                    textColor = _theme.textColorSelected;
                }
            }
            else
            {
                backColor = _theme.backColor;
                textColor = _theme.textColor;
            }

            BidiGraphics g = new BidiGraphics(e.Graphics, e.Bounds);

            // setup standard string format
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis | TextFormatFlags.NoPrefix;

            // draw background
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, e.Bounds);

            // draw top-line if necessary
            //if ( !selected )
            {
                using (Pen pen = new Pen(_theme.topLineColor))
                    g.DrawLine(pen, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - ScaleY(1));
            }

            // draw post icon
            g.DrawImage(false, _blogPostImage, new Rectangle(
                                  e.Bounds.Left + ScaleX(HORIZONTAL_INSET), e.Bounds.Top + ScaleY(TITLE_INSET),
                                  ScaleX(_blogPostImage.Width), ScaleY(_blogPostImage.Height)));

            // calculate standard text drawing metrics
            int leftMargin = ScaleX(HORIZONTAL_INSET) + ScaleX(_blogPostImage.Width) + ScaleX(HORIZONTAL_INSET);
            int topMargin = e.Bounds.Top + ScaleY(TITLE_INSET);
            // draw title line

            // post date
            string dateText = postInfo.PrettyDateDisplay;
            Size dateSize = g.MeasureText(dateText, e.Font);
            Rectangle dateRectangle = new Rectangle(
                e.Bounds.Right - ScaleX(HORIZONTAL_INSET) - dateSize.Width, topMargin, dateSize.Width, dateSize.Height);

            g.DrawText(dateText, e.Font, dateRectangle, textColor, TextFormatFlags.HorizontalCenter | TextFormatFlags.NoPrefix);

            // post title
            int titleWidth = dateRectangle.Left - leftMargin - ScaleX(DATE_PADDING);
            string titleString = String.Format(CultureInfo.CurrentCulture, "{0}", postInfo.Title);
            int fontHeight = g.MeasureText(titleString, e.Font).Height;
            Rectangle titleRectangle = new Rectangle(leftMargin, topMargin, titleWidth, fontHeight);

            g.DrawText(
                titleString,
                e.Font,
                titleRectangle, textColor, ellipsesStringFormat);

            // draw post preview

            // calculate layout rectangle
            Rectangle layoutRectangle = new Rectangle(
                leftMargin,
                topMargin + fontHeight + ScaleY(PREVIEW_INSET),
                e.Bounds.Width - leftMargin - ScaleX(HORIZONTAL_INSET),
                fontHeight * PREVIEW_LINES);

            // draw post preview
            string postPreview = postInfo.PlainTextContents;
            if (PostSource.HasMultipleWeblogs && (postInfo.BlogName != String.Empty))
                postPreview = String.Format(CultureInfo.CurrentCulture, "{0} - {1}", postInfo.BlogName, postPreview);

            g.DrawText(
                postPreview,
                e.Font, layoutRectangle, textColor, ellipsesStringFormat);

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }
        private void DrawTabFace(BidiGraphics g, Color bgColor, Color borderColor, Color lineColor)
        {
            Rectangle borderRect = ClientRectangle;

            if (!Selected)
                borderRect.Height -= 2;

            // Remove one pixel for the bottom edge of the tab.
            // We don't want it filled in by the face color as
            // that would cause the corner pixels of the tab
            // to be filled in.
            borderRect.Height -= 1;

            using (Brush b = new SolidBrush(bgColor))
                g.Graphics.FillRectangle(b, borderRect);

            borderRect.Width -= 1;

            if (Selected)
                borderRect.Y -= 1;
            else
            {
                borderRect.Height -= 1;
            }

            if (clipLeftBorder)
            {
                borderRect.X -= 1;
                borderRect.Width += 1;
            }

            if (clipRightBorder)
                borderRect.Width += 1;

            Region clip = g.Graphics.Clip;
            clip.Exclude(g.TranslateRectangle(new Rectangle(borderRect.X, borderRect.Bottom, 1, 1)));
            clip.Exclude(g.TranslateRectangle(new Rectangle(borderRect.Right, borderRect.Bottom, 1, 1)));
            g.Graphics.Clip = clip;

            using (Pen p = new Pen(borderColor))
                g.DrawRectangle(p, borderRect);

            if (!Selected)
                using (Pen p = new Pen(lineColor))
                    g.DrawLine(p, 0, 0, ClientSize.Width, 0);
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // screen invalid drawing states
            if (DesignMode || e.Index == -1)
                return;

            // get item text and image
            string itemText = Items[e.Index].ToString();
            IComboItem comboItem = (IComboItem)Items[e.Index];
            Image itemImage = comboItem.Image;

            // determine state
            bool selected = (e.State & DrawItemState.Selected) > 0;

            // calculate colors
            Color backColor, textColor;
            if (selected && Focused)
            {
                textColor = SystemColors.ControlText;
                backColor = Color.FromArgb(50, SystemColors.Highlight);
            }
            else
            {
                backColor = SystemColors.Window;
                textColor = SystemColors.ControlText;
            }
            Rectangle area = e.Bounds;
            //overlap issue in RTL builds in the selected box area ONLY
            if (area.X == 21)
            {
                area = ClientRectangle;
            }
            BidiGraphics g = new BidiGraphics(e.Graphics, area);

            // draw background (always paint white over it first)
            g.FillRectangle(Brushes.White, area);
            using (SolidBrush solidBrush = new SolidBrush(backColor))
                g.FillRectangle(solidBrush, area);

            // draw icon
            g.DrawImage(AllowMirroring, itemImage, area.Left + IMAGE_INSET, area.Top + area.Height / 2 - itemImage.Height / 2);

            // text format and drawing metrics
            TextFormatFlags ellipsesStringFormat = TextFormatFlags.VerticalCenter |
                   TextFormatFlags.WordBreak | TextFormatFlags.ExpandTabs | TextFormatFlags.WordEllipsis;
            int leftMargin = IMAGE_INSET + itemImage.Width + TEXT_INSET;

            // draw title line
            // post title
            int titleWidth = area.Right - leftMargin;
            Rectangle titleRectangle = new Rectangle(area.Left + leftMargin, area.Top, titleWidth, area.Height);
            g.DrawText(
                itemText,
                e.Font, titleRectangle, textColor, ellipsesStringFormat);

            // separator line if necessary
            if (!selected && DroppedDown)
            {
                using (Pen pen = new Pen(SystemColors.ControlLight))
                    g.DrawLine(pen, area.Left, area.Bottom - 1, area.Right, area.Bottom - 1);
            }

            // focus rectange if necessary
            e.DrawFocusRectangle();
        }