Пример #1
0
            protected override void OnDrawItem(DrawItemEventArgs e)
            {
                base.OnDrawItem(e);

                Graphics  graphics = e.Graphics;
                Rectangle bounds   = e.Bounds;

                bool selected = ((e.State & DrawItemState.Selected) != 0);
                bool disabled = ((e.State & DrawItemState.Disabled) != 0);

                if (item is CommandBarSeparator)
                {
                    Rectangle r = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 2), bounds.Width, bounds.Height);
                    ControlPaint.DrawBorder3D(graphics, r, Border3DStyle.Etched, Border3DSide.Top);
                }
                else
                {
                    this.DrawImage(graphics, bounds, selected, disabled);

                    int width = 6 + imageSize.Width;
                    this.DrawBackground(graphics, new Rectangle(bounds.X + width, bounds.Y, bounds.Width - width, bounds.Height), selected);

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        if ((this.Text != null) && (this.Text.Length != 0))
                        {
                            Size  size  = textGraphics.MeasureText(this.Text, font);
                            Point point = new Point();
                            point.X = bounds.X + 3 + imageSize.Width + 6;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, this.Text, point, selected, disabled);
                        }

                        CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                        if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                        {
                            string text = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);

                            Size size = textGraphics.MeasureText(text, font);

                            Point point = new Point();
                            point.X = bounds.X + bounds.Width - 3 - imageSize.Width - 3 - size.Width;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, text, point, selected, disabled);
                        }
                    }
                }
            }
Пример #2
0
        private void NotifyCustomDrawToolBar(ref Message m)
        {
            m.Result = (IntPtr)NativeMethods.CDRF_DODEFAULT;

            NativeMethods.DLLVERSIONINFO dvi = new NativeMethods.DLLVERSIONINFO();
            dvi.cbSize = Marshal.SizeOf(typeof(NativeMethods.DLLVERSIONINFO));
            NativeMethods.DllGetVersion(ref dvi);
            if (dvi.dwMajorVersion < 6)
            {
                NativeMethods.LPNMTBCUSTOMDRAW tbcd = (NativeMethods.LPNMTBCUSTOMDRAW)m.GetLParam(typeof(NativeMethods.LPNMTBCUSTOMDRAW));
                NativeMethods.RECT             rc   = tbcd.nmcd.rc;

                Rectangle rectangle = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

                Graphics       graphics = Graphics.FromHdc(tbcd.nmcd.hdc);
                CommandBarItem item     = items[tbcd.nmcd.dwItemSpec];

                bool hot      = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_HOT) != 0);
                bool selected = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_SELECTED) != 0);
                bool disabled = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_DISABLED) != 0);

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;
                if ((checkBox != null) && (checkBox.IsChecked))
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                }
                else if (selected)
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                }
                else if (hot)
                {
                    ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner);
                }

                Image image = item.Image;
                if (image != null)
                {
                    Size  size  = image.Size;
                    Point point = new Point(rc.left + ((rc.right - rc.left - size.Width) / 2), rc.top + ((rc.bottom - rc.top - size.Height) / 2));
                    NativeMethods.DrawImage(graphics, image, point, disabled);
                }

                m.Result = (IntPtr)NativeMethods.CDRF_SKIPDEFAULT;
            }
        }
Пример #3
0
        protected override void WndProc(ref Message m)
        {
            switch ((Msg)m.Msg)
            {
            case Msg.WM_NCPAINT:
                PaintEventArgs pe = XplatUI.PaintEventStart(ref m, Handle, false);

                Rectangle clip;
                clip = new Rectangle(0, 0, Width, Height);

                ControlPaint.DrawBorder3D(pe.Graphics, clip, Border3DStyle.Sunken);
                XplatUI.PaintEventEnd(ref m, Handle, false, pe);
                m.Result = IntPtr.Zero;
                return;
            }

            base.WndProc(ref m);
        }
Пример #4
0
        public override void PaintHeader(Graphics g, Rectangle bounds, bool alignToRight, bool isDirty)
        {
            DataGrid  dataGrid  = base.DataGrid;
            Rectangle rectangle = bounds;

            if (!dataGrid.FlatMode)
            {
                ControlPaint.DrawBorder3D(g, rectangle, Border3DStyle.RaisedInner);
                rectangle.Inflate(-1, -1);
            }
            if (base.dgTable.IsDefault)
            {
                this.PaintHeaderInside(g, rectangle, base.DataGrid.HeaderBackBrush, alignToRight, isDirty);
            }
            else
            {
                this.PaintHeaderInside(g, rectangle, base.dgTable.HeaderBackBrush, alignToRight, isDirty);
            }
        }
Пример #5
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            LinearGradientBrush brush = new LinearGradientBrush(new Point(0, 0), new Point(0, Height), startColor, endColor);

            Blend blend1 = new Blend(9);

            // Set the values in the Factors array to be all green,
            // go to all blue, and then go back to green.
            blend1.Factors = new float[] { 0.0F, 0.5F, 0.8F, 0.9F, 1.0F, 0.9F, 0.8F, 0.5F, 0.0F };

            // Set the positions.
            blend1.Positions = new float[] { 0.0F, 0.1F, 0.2F, 0.3F, 0.4F, 0.7F, 0.8F, 0.9F, 1.0F };

            brush.Blend = blend1;

            e.Graphics.FillRectangle(brush, ClientRectangle);
            ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, borderStyle);
            brush.Dispose();
        }
Пример #6
0
        public override void PaintHeader(Graphics g, Rectangle bounds, bool alignToRight, bool isDirty)
        {
            DataGrid grid = this.DataGrid;

            Rectangle insideBounds = bounds;

            if (!grid.FlatMode)
            {
                ControlPaint.DrawBorder3D(g, insideBounds, Border3DStyle.RaisedInner);
                insideBounds.Inflate(-1, -1);
            }

            if (this.dgTable.IsDefault)
            {
                PaintHeaderInside(g, insideBounds, this.DataGrid.HeaderBackBrush, alignToRight, isDirty);
            }
            else
            {
                PaintHeaderInside(g, insideBounds, this.dgTable.HeaderBackBrush, alignToRight, isDirty);
            }
        }
Пример #7
0
        /// <include file='doc\ToolStripRenderer.uex' path='docs/doc[@for="ToolStripRenderer.OnRenderBorder"]/*' />
        /// <devdoc>
        /// Draw the border around the ToolStrip.  This should be done as the last step.
        /// </devdoc>
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            ToolStrip toolStrip = e.ToolStrip;
            Graphics  g         = e.Graphics;
            Rectangle bounds    = e.ToolStrip.ClientRectangle;

            if (toolStrip is StatusStrip)
            {
                RenderStatusStripBorder(e);
            }
            else if (toolStrip is ToolStripDropDown)
            {
                ToolStripDropDown toolStripDropDown = toolStrip as ToolStripDropDown;

                // Paint the border for the window depending on whether or not we have a drop shadow effect.
                if (toolStripDropDown.DropShadowEnabled && ToolStripManager.VisualStylesEnabled)
                {
                    bounds.Width  -= 1;
                    bounds.Height -= 1;
                    e.Graphics.DrawRectangle(new Pen(SystemColors.ControlDark), bounds);
                }
                else
                {
                    ControlPaint.DrawBorder3D(e.Graphics, bounds, Border3DStyle.Raised);
                }
            }
            else
            {
                if (ToolStripManager.VisualStylesEnabled)
                {
                    e.Graphics.DrawLine(SystemPens.ButtonHighlight, 0, bounds.Bottom - 1, bounds.Width, bounds.Bottom - 1);
                    e.Graphics.DrawLine(SystemPens.InactiveBorder, 0, bounds.Bottom - 2, bounds.Width, bounds.Bottom - 2);
                }
                else
                {
                    e.Graphics.DrawLine(SystemPens.ButtonHighlight, 0, bounds.Bottom - 1, bounds.Width, bounds.Bottom - 1);
                    e.Graphics.DrawLine(SystemPens.ButtonShadow, 0, bounds.Bottom - 2, bounds.Width, bounds.Bottom - 2);
                }
            }
        }
Пример #8
0
        internal void Paint(Graphics g, Rectangle bounds, bool alignRight)
        {
            Size size = new Size(((int)g.MeasureString(this.text, this.Font).Width) + 2, this.Font.Height + 2);

            this.downButtonRect = this.GetDetailsButtonRect(bounds, alignRight);
            int detailsButtonWidth = this.GetDetailsButtonWidth();

            this.backButtonRect = this.GetBackButtonRect(bounds, alignRight, detailsButtonWidth);
            int num2 = this.backButtonVisible ? ((this.backButtonRect.Width + 3) + 4) : 0;
            int num3 = (this.downButtonVisible && !this.dataGrid.ParentRowsIsEmpty()) ? ((detailsButtonWidth + 3) + 4) : 0;
            int num4 = ((bounds.Width - 3) - num2) - num3;

            this.textRect = new Rectangle(bounds.X, bounds.Y + 1, Math.Min(num4, 4 + size.Width), 4 + size.Height);
            if (alignRight)
            {
                this.textRect.X       = bounds.Right - this.textRect.Width;
                this.backButtonRect.X = (bounds.X + 12) + detailsButtonWidth;
                this.downButtonRect.X = bounds.X + 6;
            }
            g.FillRectangle(this.backBrush, bounds);
            if (this.backButtonVisible)
            {
                this.PaintBackButton(g, this.backButtonRect, alignRight);
                if (this.backActive && (this.lastMouseLocation == CaptionLocation.BackButton))
                {
                    this.backButtonRect.Inflate(1, 1);
                    ControlPaint.DrawBorder3D(g, this.backButtonRect, this.backPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner);
                }
            }
            this.PaintText(g, this.textRect, alignRight);
            if (this.downButtonVisible && !this.dataGrid.ParentRowsIsEmpty())
            {
                this.PaintDownButton(g, this.downButtonRect);
                if (this.lastMouseLocation == CaptionLocation.DownButton)
                {
                    this.downButtonRect.Inflate(1, 1);
                    ControlPaint.DrawBorder3D(g, this.downButtonRect, this.downPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner);
                }
            }
        }
Пример #9
0
 protected override void OnPaint(PaintEventArgs e)
 {
     base.OnPaintBackground(e);
     checked
     {
         if (base.BorderStyle == BorderStyle.FixedSingle)
         {
             ControlPaint.DrawBorder(e.Graphics, new Rectangle(0, 0, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1), this._borderColor, ButtonBorderStyle.Solid);
         }
         else
         {
             if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
             {
                 ControlPaint.DrawVisualStyleBorder(e.Graphics, new Rectangle(0, 0, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1));
             }
             else
             {
                 ControlPaint.DrawBorder3D(e.Graphics, new Rectangle(0, 0, base.ClientRectangle.Width - 1, base.ClientRectangle.Height - 1), Border3DStyle.Sunken);
             }
         }
     }
 }
Пример #10
0
        private void DrawInsetBorder(Graphics g, Rectangle rect)
        {
            ControlPaint.DrawBorder3D(g, rect, Border3DStyle.Etched);

            int x = DisplayRectangle.X;
            int y = DisplayRectangle.Y;

            for (int i = 0; i < column_widths.Length - 1; i++)
            {
                x += column_widths[i] + 2;

                g.DrawLine(SystemPens.ControlDark, new Point(x, 1), new Point(x, Bottom - 3));
                g.DrawLine(Pens.White, new Point(x + 1, 1), new Point(x + 1, Bottom - 3));
            }

            for (int j = 0; j < row_heights.Length - 1; j++)
            {
                y += row_heights[j] + 2;

                g.DrawLine(SystemPens.ControlDark, new Point(1, y), new Point(Right - 3, y));
                g.DrawLine(Pens.White, new Point(1, y + 1), new Point(Right - 3, y + 1));
            }
        }
        /// <devdoc>
        ///      Called by the dataGrid when it needs the caption
        ///      to repaint.
        /// </devdoc>
        internal void Paint(Graphics g, Rectangle bounds, bool alignRight)
        {
            Size textSize = new Size((int)g.MeasureString(text, this.Font).Width + 2, this.Font.Height + 2);

            downButtonRect = GetDetailsButtonRect(bounds, alignRight);
            int downButtonWidth = GetDetailsButtonWidth();

            backButtonRect = GetBackButtonRect(bounds, alignRight, downButtonWidth);

            int backButtonArea = backButtonVisible ? backButtonRect.Width + xOffset + buttonToText : 0;
            int downButtonArea = downButtonVisible && !dataGrid.ParentRowsIsEmpty() ? downButtonWidth + xOffset + buttonToText : 0;

            int textWidthLeft = bounds.Width - xOffset - backButtonArea - downButtonArea;


            textRect = new Rectangle(
                bounds.X,
                bounds.Y + yOffset,
                Math.Min(textWidthLeft, 2 * textPadding + textSize.Width),
                2 * textPadding + textSize.Height);

            // align the caption text box, downButton, and backButton
            // if the RigthToLeft property is set to true
            if (alignRight)
            {
                textRect.X       = bounds.Right - textRect.Width;
                backButtonRect.X = bounds.X + xOffset * 4 + downButtonWidth;
                downButtonRect.X = bounds.X + xOffset * 2;
            }

            Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "text size = " + textSize.ToString());
            Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "downButtonWidth = " + downButtonWidth.ToString(CultureInfo.InvariantCulture));
            Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "textWidthLeft = " + textWidthLeft.ToString(CultureInfo.InvariantCulture));
            Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "backButtonRect " + backButtonRect.ToString());
            Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "textRect " + textRect.ToString());
            Debug.WriteLineIf(CompModSwitches.DGCaptionPaint.TraceVerbose, "downButtonRect " + downButtonRect.ToString());

            // we should use the code that is commented out
            // with today's code, there are pixels on the backButtonRect and the downButtonRect
            // that are getting painted twice
            //
            g.FillRectangle(backBrush, bounds);

            if (backButtonVisible)
            {
                PaintBackButton(g, backButtonRect, alignRight);
                if (backActive)
                {
                    if (lastMouseLocation == CaptionLocation.BackButton)
                    {
                        backButtonRect.Inflate(1, 1);
                        ControlPaint.DrawBorder3D(g, backButtonRect,
                                                  backPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner);
                    }
                }
            }
            PaintText(g, textRect, alignRight);

            if (downButtonVisible && !dataGrid.ParentRowsIsEmpty())
            {
                PaintDownButton(g, downButtonRect);
                // the rules have changed, yet again.
                // now: if we show the parent rows and the mouse is
                // not on top of this icon, then let the icon be depressed.
                // if the mouse is pressed over the icon, then show the icon pressed
                // if the mouse is over the icon and not pressed, then show the icon SunkenInner;
                //
                if (lastMouseLocation == CaptionLocation.DownButton)
                {
                    downButtonRect.Inflate(1, 1);
                    ControlPaint.DrawBorder3D(g, downButtonRect,
                                              downPressed ? Border3DStyle.SunkenInner : Border3DStyle.RaisedInner);
                }
            }
        }
Пример #12
0
        public static void DrawGroupBox(Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
        {
            Size font_size = TextRenderer.MeasureText(groupBoxText, font);

            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr;
                Rectangle           new_bounds;

                switch (state)
                {
                case GroupBoxState.Normal:
                default:
                    vsr        = new VisualStyleRenderer(VisualStyleElement.Button.GroupBox.Normal);
                    new_bounds = new Rectangle(bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);
                    break;

                case GroupBoxState.Disabled:
                    vsr        = new VisualStyleRenderer(VisualStyleElement.Button.GroupBox.Disabled);
                    new_bounds = new Rectangle(bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 2, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 2);
                    break;
                }

                if (groupBoxText == String.Empty)
                {
                    vsr.DrawBackground(g, bounds);
                }
                else
                {
                    vsr.DrawBackgroundExcludingArea(g, new_bounds, new Rectangle(bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height));
                }

                if (textColor == Color.Empty)
                {
                    textColor = vsr.GetColor(ColorProperty.TextColor);
                }

                if (groupBoxText != String.Empty)
                {
                    TextRenderer.DrawText(g, groupBoxText, font, new Point(bounds.Left + 8, bounds.Top), textColor, flags);
                }
            }
            else
            {
                // MS has a pretty big bug when rendering the non-visual styles group box.  Instead of using the height
                // part of the bounds as height, they use it as the bottom, so the boxes are drawn in completely different
                // places.  Rather than emulate this bug, we do it correctly.  After googling for a while, I don't think
                // anyone has ever actually used this class for anything, so it should be fine.  :)
                Rectangle new_bounds = new Rectangle(bounds.Left, bounds.Top + (int)(font_size.Height / 2), bounds.Width, bounds.Height - (int)(font_size.Height / 2));

                // Don't paint over the background where we are going to put the text
                var savedClip = g.Clip.Clone();

                g.SetClip(new Rectangle(bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);
                ControlPaint.DrawBorder3D(g, new_bounds, Border3DStyle.Etched);

                g.Clip = savedClip;

                if (groupBoxText != String.Empty)
                {
                    if (textColor == Color.Empty)
                    {
                        textColor = state == GroupBoxState.Normal ? SystemColors.ControlText :
                                    SystemColors.GrayText;
                    }
                    TextRenderer.DrawText(g, groupBoxText, font, new Point(bounds.Left + 11 /*8*/, bounds.Top), textColor, flags);
                }
            }
        }
Пример #13
0
            private void DrawImage(Graphics graphics, Rectangle bounds, bool selected, bool disabled)
            {
                Rectangle rectangle = new Rectangle(bounds.X, bounds.Y, imageSize.Width + 6, bounds.Height);

                Size      checkSize      = SystemInformation.MenuCheckSize;
                Rectangle checkRectangle = new Rectangle(bounds.X + 1 + ((imageSize.Width + 6 - checkSize.Width) / 2), bounds.Y + ((bounds.Height - checkSize.Height) / 2), checkSize.Width, checkSize.Height);

                CommandBarCheckBox checkBox = item as CommandBarCheckBox;

                if (this.IsFlatMenu)
                {
                    DrawBackground(graphics, rectangle, selected);

                    if ((checkBox != null) && (checkBox.IsChecked))
                    {
                        int height = bounds.Height - 2;
                        graphics.DrawRectangle(SystemPens.Highlight, new Rectangle(bounds.X + 1, bounds.Y + 1, imageSize.Width + 3, height - 1));
                        graphics.FillRectangle(SystemBrushes.Menu, new Rectangle(bounds.X + 2, bounds.Y + 2, imageSize.Width + 2, height - 2));
                    }

                    Image image = item.Image;
                    if (image != null)
                    {
                        Point point = new Point(bounds.X + 3, bounds.Y + ((bounds.Height - image.Height) / 2));
                        NativeMethods.DrawImage(graphics, image, point, disabled);
                    }
                    else
                    {
                        if ((checkBox != null) && (checkBox.IsChecked))
                        {
                            Color color = (disabled ? SystemColors.GrayText : SystemColors.MenuText);
                            this.DrawCheck(graphics, checkRectangle, color);
                        }
                    }
                }
                else
                {
                    Image image = item.Image;
                    if (image == null)
                    {
                        this.DrawBackground(graphics, rectangle, selected);

                        if ((checkBox != null) && (checkBox.IsChecked))
                        {
                            Color color = (disabled ? (selected ? SystemColors.GrayText : SystemColors.ControlDark) : (selected ? SystemColors.HighlightText : SystemColors.MenuText));
                            this.DrawCheck(graphics, checkRectangle, color);
                        }
                    }
                    else
                    {
                        DrawBackground(graphics, rectangle, false);
                        if ((checkBox != null) && (checkBox.IsChecked))
                        {
                            ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
                        }
                        else if (selected)
                        {
                            ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner);
                        }

                        Point point = new Point(bounds.X + 3, bounds.Y + ((bounds.Height - image.Height) / 2));
                        NativeMethods.DrawImage(graphics, image, point, disabled);
                    }
                }
            }
Пример #14
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (showPanels == false)
            {
                DrawSimpleText(e, 0, 0, Width, Height, Text);
            }
            else
            {
                int           left  = 0;
                Border3DStyle style = Border3DStyle.Sunken;
                if (panels.Count < 1)
                {
                    int panelWidth;
                    if (sizingGrip == true)
                    {
                        panelWidth = Width - 16;
                    }
                    else
                    {
                        panelWidth = Width;
                    }
                    ControlPaint.DrawBorder3D(g, 0, 2, panelWidth, Height - 2, Border3DStyle.SunkenOuter, Border3DSide.All);
                }
                else
                {
                    for (int i = 0; i < panels.Count; i++)
                    {
                        StatusBarPanel panel    = panels[i];
                        Icon           icon     = panel.Icon;
                        int            textLeft = left;

                        switch (panel.BorderStyle)
                        {
                        case StatusBarPanelBorderStyle.None:
                            style = Border3DStyle.Flat;
                            break;

                        case StatusBarPanelBorderStyle.Raised:
                            style = Border3DStyle.Raised;
                            break;

                        case StatusBarPanelBorderStyle.Sunken:
                            style = Border3DStyle.SunkenOuter;
                            break;
                        }
                        ControlPaint.DrawBorder3D(g, left, 4, panel.Width, Height - 4, style, Border3DSide.All);
                        if (icon != null)
                        {
                            g.DrawIcon(icon, left, (Height - icon.Height) / 2);
                            textLeft += icon.Width;
                        }
                        if (panel.Style == StatusBarPanelStyle.Text)
                        {
                            StringAlignment align = 0;
                            switch (panel.Alignment)
                            {
                            case HorizontalAlignment.Center:
                                align = StringAlignment.Center;
                                break;

                            case HorizontalAlignment.Left:
                                align = StringAlignment.Near;
                                break;

                            case HorizontalAlignment.Right:
                                align = StringAlignment.Far;
                                break;
                            }
                            DrawSimpleText(e, textLeft, 4, left + panel.Width, Height, panel.Text, align);
                        }
                        else
                        {
                            // Owner drawn
                            StatusBarDrawItemEventArgs args = new StatusBarDrawItemEventArgs(g, this.Font, new Rectangle(0, 0, panel.Width, Height), i, DrawItemState.None, panel);
                            OnDrawItem(args);
                        }
                        left += panel.Width + 2;
                    }
                }
            }

            if (sizingGrip == true)
            {
                ControlPaint.DrawSizeGrip(g, BackColor, new Rectangle(Width - 16, Height - 16, Width, Height));
            }
            base.OnPaint(e);
        }
        /// <summary>
        /// Paints the control.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected virtual void PaintControl(PaintEventArgs e)
        {
            var cbi = NativeMethods.COMBOBOXINFO.FromComboBox(this);

            string        itemText = this.SelectedIndex >= 0 ? this.GetItemText(this.SelectedItem) : string.Empty;
            ComboBoxState state    = Enabled ? currentState : ComboBoxState.Disabled;
            Rectangle     tr       = cbi.rcItem;

            /*Rectangle tr = this.ClientRectangle;
             * tr.Width -= (SystemInformation.VerticalScrollBarWidth + 2);
             * tr.Inflate(0, -2);
             * tr.Offset(1, 0);*/
            Rectangle br        = cbi.rcButton;
            bool      vsSuccess = false;

            if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
            {
                /*Rectangle r = Rectangle.Inflate(this.ClientRectangle, 1, 1);
                 * if (this.DropDownStyle != ComboBoxStyle.DropDownList)
                 * {
                 *      e.Graphics.Clear(this.BackColor);
                 *      ComboBoxRenderer.DrawTextBox(e.Graphics, r, itemText, this.Font, tr, tff, state);
                 *      ComboBoxRenderer.DrawDropDownButton(e.Graphics, br, state);
                 * }
                 * else*/
                {
                    try
                    {
                        var vr = new VisualStyleRenderer("Combobox", this.DropDownStyle == ComboBoxStyle.DropDownList ? 5 : 4, (int)state);
                        vr.DrawParentBackground(e.Graphics, this.ClientRectangle, this);
                        vr.DrawBackground(e.Graphics, this.ClientRectangle);
                        if (this.DropDownStyle != ComboBoxStyle.DropDownList)
                        {
                            br.Inflate(1, 1);
                        }
                        Rectangle cr = this.DropDownStyle == ComboBoxStyle.DropDownList ? Rectangle.Inflate(br, -1, -1) : br;
                        vr.SetParameters("Combobox", 7, (int)(br.Contains(this.PointToClient(Cursor.Position)) ? state : ComboBoxState.Normal));
                        vr.DrawBackground(e.Graphics, br, cr);
                        if (this.Focused && State != ComboBoxState.Pressed)
                        {
                            Size      sz = TextRenderer.MeasureText(e.Graphics, "Wg", this.Font, tr.Size, TextFormatFlags.Default);
                            Rectangle fr = Rectangle.Inflate(tr, 0, ((sz.Height - tr.Height) / 2) + 1);
                            ControlPaint.DrawFocusRectangle(e.Graphics, fr);
                        }
                        TextRenderer.DrawText(e.Graphics, itemText, this.Font, tr, this.ForeColor, tff);
                        vsSuccess = true;
                    }
                    catch { }
                }
            }

            if (!vsSuccess)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("CR:{0};ClR:{1};Foc:{2};St:{3};Tx:{4}", ClientRectangle, e.ClipRectangle, this.Focused, state, itemText));
                e.Graphics.Clear(this.BackColor);
                ControlPaint.DrawBorder3D(e.Graphics, this.ClientRectangle, Border3DStyle.Sunken);
                ControlPaint.DrawComboButton(e.Graphics, br, this.Enabled ? (state == ComboBoxState.Pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive);
                //using (var bb = new SolidBrush(this.BackColor))
                //	e.Graphics.FillRectangle(bb, tr);
                if (this.Focused)
                {
                    Size      sz = TextRenderer.MeasureText(e.Graphics, "Wg", this.Font, tr.Size, TextFormatFlags.Default);
                    Rectangle fr = Rectangle.Inflate(tr, 0, ((sz.Height - tr.Height) / 2) + 1);
                    e.Graphics.FillRectangle(SystemBrushes.Highlight, fr);
                    ControlPaint.DrawFocusRectangle(e.Graphics, fr);                     //, this.ForeColor, SystemColors.Highlight);
                }
                TextRenderer.DrawText(e.Graphics, itemText, this.Font, tr, this.Focused ? SystemColors.HighlightText : this.ForeColor, tff);
            }
        }
        /// <summary>
        /// Paints the control.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected virtual void PaintControl(PaintEventArgs e)
        {
            var cbi = NativeMethods.COMBOBOXINFO.FromComboBox(this);

            var       itemText = SelectedIndex >= 0 ? GetItemText(SelectedItem) : string.Empty;
            var       state    = Enabled ? currentState : ComboBoxState.Disabled;
            Rectangle tr       = cbi.rcItem;

            /*Rectangle tr = this.ClientRectangle;
             * tr.Width -= (SystemInformation.VerticalScrollBarWidth + 2);
             * tr.Inflate(0, -2);
             * tr.Offset(1, 0);*/
            Rectangle br        = cbi.rcButton;
            var       vsSuccess = false;

            if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
            {
                /*Rectangle r = Rectangle.Inflate(this.ClientRectangle, 1, 1);
                 * if (this.DropDownStyle != ComboBoxStyle.DropDownList)
                 * {
                 *      e.Graphics.Clear(this.BackColor);
                 *      ComboBoxRenderer.DrawTextBox(e.Graphics, r, itemText, this.Font, tr, tff, state);
                 *      ComboBoxRenderer.DrawDropDownButton(e.Graphics, br, state);
                 * }
                 * else*/
                {
                    try
                    {
                        var vr = new VisualStyleRenderer("Combobox", DropDownStyle == ComboBoxStyle.DropDownList ? 5 : 4, (int)state);
                        vr.DrawParentBackground(e.Graphics, ClientRectangle, this);
                        vr.DrawBackground(e.Graphics, ClientRectangle);
                        if (DropDownStyle != ComboBoxStyle.DropDownList)
                        {
                            br.Inflate(1, 1);
                        }
                        var cr = DropDownStyle == ComboBoxStyle.DropDownList ? Rectangle.Inflate(br, -1, -1) : br;
                        vr.SetParameters("Combobox", 7, (int)(br.Contains(PointToClient(Cursor.Position)) ? state : ComboBoxState.Normal));
                        vr.DrawBackground(e.Graphics, br, cr);
                        if (Focused && State != ComboBoxState.Pressed)
                        {
                            var sz = TextRenderer.MeasureText(e.Graphics, "Wg", Font, tr.Size, TextFormatFlags.Default);
                            var fr = Rectangle.Inflate(tr, 0, (sz.Height - tr.Height) / 2 + 1);
                            ControlPaint.DrawFocusRectangle(e.Graphics, fr);
                        }
                        var fgc = Enabled ? ForeColor : SystemColors.GrayText;
                        TextRenderer.DrawText(e.Graphics, itemText, Font, tr, fgc, tff);
                        vsSuccess = true;
                    }
                    catch { }
                }
            }

            if (!vsSuccess)
            {
                Diagnostics.Debug.WriteLine($"CR:{ClientRectangle};ClR:{e.ClipRectangle};Foc:{Focused};St:{state};Tx:{itemText}");
                var focusedNotPressed = Focused && state != ComboBoxState.Pressed;
                var bgc = Enabled ? (focusedNotPressed ? SystemColors.Highlight : BackColor) : SystemColors.Control;
                var fgc = Enabled ? (focusedNotPressed ? SystemColors.HighlightText : ForeColor) : SystemColors.GrayText;
                e.Graphics.Clear(bgc);
                ControlPaint.DrawBorder3D(e.Graphics, ClientRectangle, Border3DStyle.Sunken);
                ControlPaint.DrawComboButton(e.Graphics, br, Enabled ? (state == ComboBoxState.Pressed ? ButtonState.Pushed : ButtonState.Normal) : ButtonState.Inactive);
                tr = new Rectangle(tr.X + 3, tr.Y + 1, tr.Width - 4, tr.Height - 2);
                TextRenderer.DrawText(e.Graphics, itemText, Font, tr, fgc, tff);
                if (focusedNotPressed)
                {
                    var fr = Rectangle.Inflate(cbi.rcItem, -1, -1);
                    fr.Height++;
                    fr.Width++;
                    ControlPaint.DrawFocusRectangle(e.Graphics, fr, fgc, bgc);
                    e.Graphics.DrawRectangle(SystemPens.Window, cbi.rcItem);
                }
            }
        }