private void DrawImage(Graphics g, Rectangle imageRect)
 {
     if ((ImageList != null && ImageIndex >= 0 && ImageIndex < ImageList.Images.Count) || Image != null)
     {
         if (ImageList != null && ImageIndex >= 0 && ImageIndex < ImageList.Images.Count)
         {
             if (Enabled)
             {
                 ImageList.Draw(g, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height, ImageIndex);
             }
             else
             {
                 StiControlPaint.DrawImageDisabled(g, ImageList.Images[ImageIndex], imageRect.Left, imageRect.Top);
             }
         }
         else
         {
             if (Enabled)
             {
                 g.DrawImage(Image, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
             }
             else
             {
                 StiControlPaint.DrawImageDisabled(g, Image, imageRect.Left, imageRect.Top);
             }
         }
     }
 }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            DrawItemEventHandler handler = GetDrawItemHandler();

            if (handler == null)
            {
                Graphics  g        = e.Graphics;
                Rectangle itemRect = e.Bounds;
                if ((e.State & DrawItemState.Selected) > 0)
                {
                    itemRect.Width--;
                }
                DrawItemState state = e.State;

                int    imageIndex = UseFirstImage ? 0 : e.Index;
                string text       = Text;
                if (e.Index != -1)
                {
                    text = this.GetItemText(Items[e.Index]);
                }

                StiControlPaint.DrawItem(g, itemRect, state, text, ImageList, imageIndex, Font, BackColor, ForeColor, RightToLeft);
            }
            else
            {
                handler(this, e);
            }
        }
Beispiel #3
0
        public Rectangle GetButtonRect(Rectangle bounds)
        {
            if (!ShowButton)
            {
                return(Rectangle.Empty);
            }

            Rectangle rect = StiControlPaint.GetButtonRect(bounds, Flat, ButtonWidth, RightToLeft);

            if (RightToLeft != RightToLeft.Yes)
            {
                rect.X--;
            }
            rect.Height--;

            if (ButtonAlign == StiButtonAlign.Right)
            {
                return(rect);
            }
            else
            {
                int borderWidth = (int)SystemInformation.Border3DSize.Width;
                if (Flat)
                {
                    borderWidth = 1;
                }

                rect.X      = borderWidth;
                rect.Width -= 2;
                return(rect);
            }
        }
 private static void DrawImage(Graphics g, bool isEnabled, Rectangle imageRect, ImageList imageList, int imageIndex, Image image)
 {
     if ((imageList != null && imageIndex >= 0 && imageIndex < imageList.Images.Count) || image != null)
     {
         if (imageList != null && imageIndex >= 0 && imageIndex < imageList.Images.Count)
         {
             if (isEnabled)
             {
                 imageList.Draw(g, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height, imageIndex);
             }
             else
             {
                 StiControlPaint.DrawImageDisabled(g, imageList.Images[imageIndex], imageRect.Left, imageRect.Top);
             }
         }
         else
         {
             if (isEnabled)
             {
                 g.DrawImage(image, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
             }
             else
             {
                 StiControlPaint.DrawImageDisabled(g, image, imageRect.Left, imageRect.Top);
             }
         }
     }
 }
        protected override void OnPaint(PaintEventArgs p)
        {
            Graphics g = p.Graphics;

            Rectangle rect = new Rectangle(0, 0, Width - 1, Height - 1);

            if (this.ReadOnly)
            {
                IsMouseOver = false;
            }

            if ((!this.Enabled) || this.ReadOnly)
            {
                g.FillRectangle(SystemBrushes.Window, rect);
            }

            if (VisualStyleInformation.IsEnabledByUser && VisualStyleInformation.IsSupportedByOS)
            {
                try
                {
                    VisualStyleElement element = null;

                    if (!this.Enabled)
                    {
                        element = VisualStyleElement.TextBox.TextEdit.Disabled;
                    }
                    else if (this.Focused)
                    {
                        element = VisualStyleElement.TextBox.TextEdit.Focused;
                    }
                    else if (IsMouseOver)
                    {
                        element = VisualStyleElement.TextBox.TextEdit.Hot;
                    }
                    else
                    {
                        element = VisualStyleElement.TextBox.TextEdit.Normal;
                    }

                    if (VisualStyleRenderer.IsElementDefined(element))
                    {
                        VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                        renderer.DrawBackground(g, rect);
                        return;
                    }
                }
                catch
                {
                }
            }
            if (this.AllowDrawBorder)
            {
                StiControlPaint.DrawBorder(g, rect, (IsMouseOver | Focused) & HotFocus, Flat);
            }
        }
Beispiel #6
0
        private static Rectangle GetDownButtonRect(Rectangle clientRect, bool flat, RightToLeft rightToLeft)
        {
            var rect = StiControlPaint.GetButtonRect(clientRect, flat, rightToLeft);
            int size = rect.Height / 2 + 2;

            if (flat)
            {
                return(new Rectangle(rect.X, rect.Y + size, rect.Width, rect.Height - size));
            }
            return(new Rectangle(rect.X, rect.Y + size - 1, rect.Width, rect.Height - size + 1));
        }
Beispiel #7
0
 public static void DrawTextBox(Graphics g, Rectangle rect, string text, Font font,
                                Color foreColor, Color backColor,
                                bool isMouseOver, bool isFocused, bool flat, bool drawBorder)
 {
     using (var brush = new SolidBrush(backColor))
     {
         g.FillRectangle(brush, rect);
     }
     if (drawBorder)
     {
         StiControlPaint.DrawBorder(g, rect, isMouseOver | isFocused, flat);
     }
 }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if ((e.Index != -1 || drawCombo) && Enabled)
            {
                string fontName = SelectedFont.Name;

                if (e.Index != -1)
                {
                    fontName = Items[e.Index].ToString();
                }

                Rectangle itemRect = e.Bounds;
                if ((e.State & DrawItemState.Selected) > 0)
                {
                    itemRect.Width--;
                }

                StiControlPaint.DrawItem(e.Graphics, itemRect, e.State, fontName,
                                         null, e.Index, Font, BackColor, ForeColor, 30, base.RightToLeft);

                var rect = new Rectangle(e.Bounds.X, e.Bounds.Y, 28, e.Bounds.Height - 1);
                var g    = e.Graphics;

                if (((e.State & DrawItemState.Focus) > 0) || ((e.State & DrawItemState.Selected) > 0))
                {
                    g.DrawRectangle(StiPens.SelectedText, rect);
                }

                if (Enabled)
                {
                    #region Sample draw
                    using (var sf = new StringFormat())
                    {
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Alignment     = StringAlignment.Center;
                        sf.FormatFlags   = StringFormatFlags.NoWrap;

                        if (this.RightToLeft == RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }

                        using (var fnt = new Font(fontName, 10))
                        {
                            g.DrawString("ab", fnt, StiBrushes.SelectedText, rect, sf);
                        }
                    }
                    #endregion
                }
            }
        }
 protected void DrawDropDownArrow(Graphics g, Rectangle rect)
 {
     if (IsDrawDropDownArrow || DropDownMenu != null)
     {
         if (Enabled)
         {
             g.DrawImage(dropDownArrowBitmap, rect.X, rect.Y, rect.Width, rect.Height);
         }
         else
         {
             StiControlPaint.DrawImageDisabled(g, dropDownArrowBitmap, rect.Left, rect.Top);
         }
     }
 }
Beispiel #10
0
        private void Draw()
        {
            using (Graphics g = Graphics.FromHwnd(this.Handle))
            {
                Rectangle rect = new Rectangle(
                    this.ClientRectangle.X,
                    this.ClientRectangle.Y,
                    this.ClientRectangle.Width - 1,
                    this.ClientRectangle.Height - 1);

                if (Flat)
                {
                    StiControlPaint.DrawBorder(g, rect, isMouseOver | this.Focused, Flat);
                }
            }
        }
        private void DrawItem(bool web, object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            if (e.Index != -1)
            {
                Color  color     = Color.Empty;
                string colorName = null;

                if (web)
                {
                    color     = StiColors.Colors[e.Index];
                    colorName = StiLocalization.Get("PropertyColor", color.Name);
                }
                else
                {
                    color     = StiColors.SystemColors[e.Index];
                    colorName = StiLocalization.Get("PropertySystemColors", color.Name);
                }

                var g    = e.Graphics;
                var rect = e.Bounds;
                if ((e.State & DrawItemState.Selected) > 0)
                {
                    rect.Width--;
                }

                var colorRect = new Rectangle(rect.X + 2, rect.Y + 2, 22, rect.Height - 5);
                var textRect  = new Rectangle(colorRect.Right + 2, rect.Y, rect.Width - colorRect.X, rect.Height);

                StiControlPaint.DrawItem(g, rect, e.State, SystemColors.Window, SystemColors.ControlText);

                using (var brush = new SolidBrush(color))
                {
                    g.FillRectangle(brush, colorRect);
                }
                g.DrawRectangle(Pens.Black, colorRect);

                using (var sf = new StringFormat())
                {
                    if (this.RightToLeft == RightToLeft.Yes)
                    {
                        sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }

                    g.DrawString(colorName, Font, Brushes.Black, textRect, sf);
                }
            }
        }
Beispiel #12
0
        private void DrawMenuItemImage(Graphics g, DrawItemEventArgs e, MenuItem item, bool rightToLeft)
        {
            Rectangle rect = e.Bounds;

            rect.Location = new Point(0, 0);
            Image image = null;

            var imageList  = GetImageList(item);
            int imageIndex = GetImageIndex(item);

            if (imageList != null && imageIndex != -1 && imageIndex < imageList.Images.Count)
            {
                image = imageList.Images[imageIndex];
            }

            if (image != null)
            {
                if (rightToLeft)
                {
                    rect = new Rectangle(
                        rect.Right - MenuBarWidth + (MenuBarWidth - imageList.Images[imageIndex].Width) / 2,
                        rect.Y + (ImageSize - imageList.Images[imageIndex].Height) / 2,
                        image.Width,
                        image.Height);
                }
                else
                {
                    rect = new Rectangle(
                        (MenuBarWidth - imageList.Images[imageIndex].Width) / 2,
                        rect.Y + (ImageSize - imageList.Images[imageIndex].Height) / 2,
                        image.Width,
                        image.Height);
                }
            }

            if (image != null)
            {
                if (item.Enabled)
                {
                    imageList.Draw(g, rect.X, rect.Y, rect.Width, rect.Height, imageIndex);
                }
                else
                {
                    StiControlPaint.DrawImageDisabled(g, image as Bitmap, rect.X, rect.Y);
                }
            }
        }
        protected override void Draw(bool fillContent)
        {
            base.Draw(fillContent);
            using (var g = Graphics.FromHwnd(this.Handle))
            {
                Rectangle rect = StiControlPaint.GetContentRect(new Rectangle(0, 0, Width - 1, Height - 1),
                                                                true, RightToLeft);
                rect.Inflate(-2, -2);
                //rect.Width--;
                rect.Height++;

                var args = new DrawItemEventArgs(g, Font, rect, -1,
                                                 Focused ? DrawItemState.Selected : DrawItemState.Default);

                drawCombo = true;
                OnDrawItem(args);
                drawCombo = false;
            }
        }
Beispiel #14
0
        protected override Rectangle GetContentRect()
        {
            Rectangle contentRect = StiControlPaint.GetContentRect(this.ClientRectangle, Flat, RightToLeft);
            Rectangle buttonRect  = GetButtonRect(this.ClientRectangle);

            buttonRect.Width  += 2;
            contentRect.Width -= (buttonRect.Width - SystemInformation.HorizontalScrollBarArrowWidth +
                                  SystemInformation.Border3DSize.Width);

            if (ButtonAlign == StiButtonAlign.Right)
            {
                contentRect.X += 2;
                return(contentRect);
            }
            else
            {
                contentRect.X += buttonRect.Width;
                return(contentRect);
            }
        }
        public static void DrawComboBox(Graphics g, Rectangle rect, string text, Font font,
                                        Color foreColor, Color backColor,
                                        RightToLeft rightToLeft,
                                        bool isEnabled, bool isMouseOver, bool isMouseOverButton,
                                        bool isDroppedDown, bool isFocused, bool fillContent, ComboBoxStyle comboBoxStyle, Image buttonBitmap,
                                        bool flat)
        {
            if (fillContent)
            {
                using (var brush = new SolidBrush(backColor))
                {
                    g.FillRectangle(brush, rect);
                }
            }

            StiControlPaint.DrawBorder(g, rect, isMouseOver | isFocused, flat);

            if (buttonBitmap != null)
            {
                if (comboBoxStyle != ComboBoxStyle.Simple)
                {
                    var buttonRect = StiControlPaint.GetButtonRect(rect, flat, rightToLeft);
                    StiControlPaint.DrawButton(g, buttonRect, buttonBitmap, isDroppedDown, isFocused | isMouseOver,
                                               isMouseOverButton, isEnabled, flat);
                }
            }

            if (text != null)
            {
                using (var sf = new StringFormat())
                    using (var brush = new SolidBrush(foreColor))
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        g.DrawString(text, font, brush, rect, sf);
                    }
            }
        }
Beispiel #16
0
        private void DrawMenuItemCheck(Graphics g, DrawItemEventArgs e, MenuItem item, bool rightToLeft)
        {
            var rect = e.Bounds;

            rect.Location = new Point(0, 0);
            if (item.Checked)
            {
                rect.X++;
                rect.Y++;

                if (rightToLeft)
                {
                    rect.X = rect.Right - (MenuBarWidth - 1);
                }
                rect.Width   = (MenuBarWidth - 4);
                rect.Height -= 3;

                g.FillRectangle(StiBrushes.Selected, rect);
                g.DrawRectangle(StiPens.SelectedText, rect);

                var imageList  = GetImageList(item);
                int imageIndex = GetImageIndex(item);

                if (!(imageList != null && imageIndex != -1 && imageIndex < imageList.Images.Count))
                {
                    if (rightToLeft)
                    {
                        StiControlPaint.DrawCheck(g, e.Bounds.Right - MenuBarWidth + ImageSize / 2, rect.Y + ImageSize / 2, true);
                    }
                    else
                    {
                        StiControlPaint.DrawCheck(g, ImageSize / 2, rect.Y + ImageSize / 2, true);
                    }
                }
            }
        }
Beispiel #17
0
        protected virtual void PaintButtons(Graphics g, Rectangle buttonRect, Image bmp,
                                            bool isPressed, bool isMouseOverButton)
        {
            if (VisualStyleInformation.IsEnabledByUser && VisualStyleInformation.IsSupportedByOS)
            {
                buttonRect.Inflate(1, 1);
                buttonRect.X     += 1;
                buttonRect.Width -= 1;

                VisualStyleElement element = null;

                if (DesignMode)
                {
                    element = VisualStyleElement.ComboBox.DropDownButton.Normal;
                }
                else if (isPressed)
                {
                    element = VisualStyleElement.ComboBox.DropDownButton.Pressed;
                }
                else if (!Enabled)
                {
                    element = VisualStyleElement.ComboBox.DropDownButton.Disabled;
                }
                else
                {
                    element = VisualStyleElement.ComboBox.DropDownButton.Normal;
                }

                try
                {
                    if (VisualStyleRenderer.IsElementDefined(element))
                    {
                        //if (bmp != null)
                        {
                            element = VisualStyleElement.Button.PushButton.Normal;

                            if (DesignMode)
                            {
                                element = VisualStyleElement.Button.PushButton.Normal;
                            }
                            else if (isPressed)
                            {
                                element = VisualStyleElement.Button.PushButton.Pressed;
                            }
                            //else if (IsMouseOver) element = VisualStyleElement.Button.PushButton.Hot;
                            else if (!Enabled)
                            {
                                element = VisualStyleElement.Button.PushButton.Disabled;
                            }
                            else
                            {
                                element = VisualStyleElement.Button.PushButton.Normal;
                            }

                            if (VisualStyleRenderer.IsElementDefined(element))
                            {
                                buttonRect.Inflate(1, 1);
                                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                                renderer.DrawBackground(g, buttonRect);

                                if (bmp == null)
                                {
                                    bmp = dropDownButtonBitmap;
                                }
                                Rectangle imageRect = new Rectangle(
                                    buttonRect.X + (buttonRect.Width - bmp.Width) / 2 + 1,
                                    buttonRect.Y + (buttonRect.Height - bmp.Height) / 2 + 1,
                                    bmp.Width, bmp.Height);

                                renderer.DrawImage(g, imageRect, bmp);

                                return;
                            }
                        }

                        /*
                         * else
                         * {
                         *  if (DesignMode) element = VisualStyleElement.ComboBox.DropDownButton.Normal;
                         *  else if (isPressed) element = VisualStyleElement.ComboBox.DropDownButton.Pressed;
                         *  //else if (IsMouseOver) element = VisualStyleElement.ComboBox.DropDownButton.Hot;
                         *  else if (!Enabled) element = VisualStyleElement.ComboBox.DropDownButton.Disabled;
                         *  else element = VisualStyleElement.ComboBox.DropDownButton.Normal;
                         *
                         *  if (VisualStyleRenderer.IsElementDefined(element))
                         *  {
                         *      VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                         *      renderer.DrawBackground(g, buttonRect);
                         *  }
                         * }*/
                    }
                }
                catch
                {
                }
            }
            else
            {
                StiControlPaint.DrawButton(g, buttonRect, bmp, isPressed, Focused | IsMouseOver,
                                           isMouseOverButton, this.Enabled, Flat);

                if (ButtonBitmap == null)
                {
                    Rectangle imageRect = new Rectangle(
                        buttonRect.X + (buttonRect.Width - dropDownButtonBitmap.Width) / 2,
                        buttonRect.Y + (buttonRect.Height - dropDownButtonBitmap.Height) / 2,
                        dropDownButtonBitmap.Width, dropDownButtonBitmap.Height);
                    g.DrawImage(dropDownButtonBitmap, imageRect);
                }
            }
        }
        protected override void OnPaint(PaintEventArgs p)
        {
            var g    = p.Graphics;
            var rect = new Rectangle(0, 0, Width, Height);

            if (BackgroundImage == null)
            {
                if (ControlStyle == StiControlStyle.Office2013Blue)
                {
                    using (var brush = new SolidBrush(Color.White))
                    {
                        g.FillRectangle(brush, rect);
                    }
                }
                else if (ControlStyle == StiControlStyle.Office2010)
                {
                    using (var brush = new SolidBrush(Color.FromArgb(245, 245, 245)))
                    {
                        g.FillRectangle(brush, rect);
                    }
                }
                else
                {
                    using (var brush = StiBrushes.GetControlBrush(rect, 90))
                    {
                        g.FillRectangle(brush, rect);
                    }
                }
            }
            else
            {
                StiControlPaint.DrawImageBackground(g, BackgroundImage, rect);
            }

            using (var penDark = new Pen(StiColorUtils.Dark(SystemColors.Control, 30)))
            {
                if (ControlStyle == StiControlStyle.Office2013Blue || ControlStyle == StiControlStyle.Office2010)
                {
                    penDark.Color       = Color.FromArgb(198, 198, 198);
                    penDark.DashPattern = new float[] { 1f, 2f };

                    if (lineStyle == StiToolBarLineStyle.Bottom)
                    {
                        g.DrawLine(penDark, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                    }
                    else if (lineStyle == StiToolBarLineStyle.All)
                    {
                        g.DrawRectangle(penDark, rect.X, rect.Y, rect.Right - 1, rect.Bottom - 1);
                    }
                    else
                    {
                        g.DrawLine(penDark, rect.X, rect.Top, rect.Right - 1, rect.Top);
                        g.DrawLine(penDark, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                    }
                }
                else
                {
                    g.DrawLine(penDark, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                    g.DrawLine(penDark, rect.Right - 1, rect.Bottom - 1, rect.Right - 1, rect.Y);
                }
            }

            if (ControlStyle == StiControlStyle.Flat)
            {
                int y = (Height - 16) / 2;
                int x = 4;
                if (this.RightToLeft == RightToLeft.Yes)
                {
                    x = this.Width - 6;
                }
                DrawDot(g, x, y);
                DrawDot(g, x, y + 4);
                DrawDot(g, x, y + 8);
                DrawDot(g, x, y + 12);
            }
        }
Beispiel #19
0
        public static void DrawNumericUpDown(Graphics g,
                                             Rectangle rect,
                                             string text, Font font,
                                             Color foreColor, Color backColor,
                                             RightToLeft rightToLeft,
                                             bool isEnabled, bool readOnly, bool isMouseOver,
                                             bool isUpMouseOver, bool isDownMouseOver,
                                             bool isUpPressed, bool isDownPressed, bool isFocused,
                                             bool flat, bool fillContent,
                                             Bitmap buttonUpBitmap, Bitmap buttonDownBitmap)
        {
            if (isEnabled)
            {
                text = string.Empty;
            }

            if (fillContent)
            {
                using (var brush = new SolidBrush(backColor))
                {
                    g.FillRectangle(brush, rect);
                }
            }

            if (!isEnabled)
            {
                using (var brush = new SolidBrush(SystemColors.Control))
                {
                    var rcContent = rect;
                    rcContent.X      += 2;
                    rcContent.Y      += 2;
                    rcContent.Height -= 3;
                    rcContent.Width  -= 2;
                    g.FillRectangle(brush, rcContent);
                }
            }

            var upButtonRect   = GetUpButtonRect(rect, flat, rightToLeft);
            var downButtonRect = GetDownButtonRect(rect, flat, rightToLeft);
            var contentRect    = StiControlPaint.GetContentRect(rect, flat, rightToLeft);

            contentRect.Height++;

            if (readOnly)
            {
                isMouseOver = false;
            }

            StiControlPaint.DrawBorder(g, rect, isMouseOver | isFocused, flat);

            #region Paint up button
            Color color = SystemColors.ControlDark;

            if (isUpMouseOver)
            {
                color = StiColors.SelectedText;
            }
            if (buttonUpBitmap != null && buttonDownBitmap != null)
            {
                StiControlPaint.DrawButton(g, upButtonRect, buttonUpBitmap, isUpPressed, isUpMouseOver | isFocused,
                                           isUpMouseOver, isEnabled, flat);
            }
            #endregion

            #region Paint down button
            color = SystemColors.ControlDark;

            if (isDownMouseOver)
            {
                color = StiColors.SelectedText;
            }
            if (buttonUpBitmap != null && buttonDownBitmap != null)
            {
                StiControlPaint.DrawButton(g, downButtonRect, buttonDownBitmap, isDownPressed, isDownMouseOver | isFocused,
                                           isDownMouseOver, isEnabled, flat);
            }
            #endregion

            if (text != null)
            {
                Color textColor = foreColor;
                if (!isEnabled)
                {
                    textColor = SystemColors.ControlDark;
                }
                using (var sf = new StringFormat())
                    using (var brush = new SolidBrush(textColor))
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        g.DrawString(text, font, brush, rect, sf);
                    }
            }

            if (isMouseOver)
            {
                g.DrawRectangle(StiPens.SelectedText, rect);
            }
        }
Beispiel #20
0
        public static void DrawCheckBox(Graphics g, Rectangle rect, string text, Font font,
                                        Color foreColor, Color backColor,
                                        RightToLeft rightToLeft, bool isEnabled,
                                        bool isMouseOver, bool isFocused, bool drawLine, bool isChecked, CheckState checkState,
                                        Appearance appearance)
        {
            Rectangle checkRect = Rectangle.Empty;
            Rectangle textRect  = Rectangle.Empty;

            textRect = new Rectangle(rect.X + 4, rect.Y, rect.Width - 4, rect.Height);
            if (rightToLeft == RightToLeft.No)
            {
                checkRect = new Rectangle(rect.X, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }
            else
            {
                checkRect = new Rectangle(rect.Right - 15, rect.Y + (rect.Height - 12) / 2 - 1, 12, 12);
            }

            if (appearance == Appearance.Normal)
            {
                if (rightToLeft == RightToLeft.No)
                {
                    textRect.X     += 10;
                    textRect.Width -= 10;
                }
                else
                {
                    textRect.Width -= 16;
                }

                #region PaintLine
                if (drawLine)
                {
                    using (Pen penLight = new Pen(StiColorUtils.Light(SystemColors.Control, 30)),
                           penDark = new Pen(StiColorUtils.Dark(SystemColors.Control, 50)))
                    {
                        int strWidth = (int)g.MeasureString(text, font).Width;

                        int posX = strWidth + 16 + rect.X;
                        int posY = rect.Y + rect.Height / 2;

                        if (posX < rect.Right)
                        {
                            g.DrawLine(penDark, posX, posY, rect.Right, posY);
                            g.DrawLine(penLight, posX, posY + 1, rect.Right, posY + 1);
                        }
                    }
                }
                #endregion

                if (isEnabled)
                {
                    using (var brush = new LinearGradientBrush(checkRect, StiColors.ContentDark, SystemColors.ControlLightLight, 45))
                    {
                        g.FillRectangle(brush, checkRect);
                    }
                }
                else
                {
                    g.FillRectangle(SystemBrushes.Control, checkRect);
                }

                if (isEnabled && (isMouseOver || isFocused))
                {
                    g.DrawRectangle(StiPens.SelectedText, checkRect);
                }
                else
                {
                    g.DrawRectangle(SystemPens.ControlDark, checkRect);
                }

                if (isChecked || checkState == CheckState.Indeterminate)
                {
                    StiControlPaint.DrawCheck(g, checkRect.X + 6, checkRect.Y + 6, isEnabled);
                }

                if (checkState == CheckState.Indeterminate)
                {
                    using (var brush = new SolidBrush(Color.FromArgb(200, SystemColors.Control)))
                    {
                        g.FillRectangle(brush,
                                        checkRect.X + 1, checkRect.Y + 1, checkRect.Width - 2, checkRect.Height - 2);
                    }
                }

                #region Paint focus
                if (isFocused)
                {
                    Rectangle focusRect = textRect;
                    SizeF     sizeText  = g.MeasureString(text, font);
                    focusRect.Width  = (int)sizeText.Width;
                    focusRect.Y      = (focusRect.Height - ((int)sizeText.Height + 2)) / 2;
                    focusRect.Height = (int)sizeText.Height + 2;

                    if (rightToLeft == RightToLeft.Yes)
                    {
                        focusRect.X = textRect.Right - focusRect.Width;
                    }

                    ControlPaint.DrawFocusRectangle(g, focusRect);
                }
                #endregion
            }
            else
            {
                StiButton.DrawButton(g, rect, text, font, foreColor, backColor, null, -1, null, rightToLeft,
                                     false, isEnabled, isMouseOver, isChecked, false, isFocused,
                                     ContentAlignment.BottomCenter, ContentAlignment.MiddleCenter);
            }

            #region Paint string
            if (appearance == Appearance.Normal)
            {
                using (var sf = new StringFormat())
                    using (var foreBrush = new SolidBrush(foreColor))
                    {
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        sf.HotkeyPrefix  = HotkeyPrefix.Show;

                        if (rightToLeft == RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }

                        if (isEnabled)
                        {
                            g.DrawString(text, font, foreBrush, textRect, sf);
                        }
                        else
                        {
                            ControlPaint.DrawStringDisabled(g, text, font, backColor,
                                                            textRect, sf);
                        }
                    }
            }
            #endregion
        }
        protected override void OnPaint(PaintEventArgs p)
        {
            base.OnPaint(p);

            Graphics g = p.Graphics;

            Rectangle colorRect = Rectangle.Empty;
            Rectangle textRect  = Rectangle.Empty;

            Rectangle buttonRect  = StiControlPaint.GetButtonRect(this.ClientRectangle, true, RightToLeft);
            Rectangle contentRect = StiControlPaint.GetContentRect(this.ClientRectangle, true, RightToLeft);
            Rectangle rect        = new Rectangle(0, 0, Width - 1, Height - 1);

            if (showColorBox)
            {
                if (showColorName)
                {
                    colorRect = new Rectangle(rect.X + 4, rect.Y + 4, 22, Height - 9);
                    if (RightToLeft == RightToLeft.Yes)
                    {
                        colorRect.X = rect.Width - colorRect.Width - 4;
                    }
                }
                else
                {
                    colorRect = new Rectangle(rect.X + 4, rect.Y + 4,
                                              Width - buttonRect.Width - 10, Height - 9);

                    if (RightToLeft == RightToLeft.Yes)
                    {
                        colorRect.X = rect.Width - colorRect.Width - 4;
                    }
                }
            }

            if (showColorName)
            {
                if (showColorBox)
                {
                    textRect = new Rectangle(colorRect.Right + 2, 1,
                                             Width - colorRect.Width - buttonRect.Width - 4, Height - 2);

                    if (RightToLeft == RightToLeft.Yes)
                    {
                        textRect.X = contentRect.X - 4;
                    }
                }
                else
                {
                    textRect = new Rectangle(2, 1, Width - buttonRect.Width - 2, Height - 2);
                    if (RightToLeft == RightToLeft.Yes)
                    {
                        textRect.X = contentRect.X - 4;
                    }
                }
            }

            #region Paint focus
            if (this.Focused)
            {
                Rectangle focusRect = GetContentRect();
                focusRect.X -= 1;
                focusRect.Y += 1;
                focusRect.Width--;
                focusRect.Height -= 2;
                ControlPaint.DrawFocusRectangle(g, focusRect);
            }
            #endregion

            #region Paint color
            if (showColorBox)
            {
                using (var brush = new SolidBrush(SelectedColor))
                    g.FillRectangle(brush, colorRect);
                if (this.Enabled)
                {
                    g.DrawRectangle(Pens.Black, colorRect);
                }
                else
                {
                    g.DrawRectangle(SystemPens.ControlDark, colorRect);
                }
            }
            #endregion

            #region Paint color name
            if (showColorName)
            {
                using (var sf = new StringFormat())
                {
                    sf.LineAlignment = StringAlignment.Center;
                    sf.FormatFlags   = StringFormatFlags.NoWrap;

                    if (this.RightToLeft == RightToLeft.Yes)
                    {
                        sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }

                    string colorName = null;
                    if (SelectedColor.IsSystemColor)
                    {
                        colorName = StiLocalization.Get("PropertySystemColors", SelectedColor.Name);
                    }
                    else if (SelectedColor.IsKnownColor)
                    {
                        colorName = StiLocalization.Get("PropertyColor", SelectedColor.Name);
                    }
                    else
                    {
                        colorName =
                            StiLocalization.Get("FormColorBoxPopup", "Color") +
                            "[A=" + SelectedColor.A.ToString() +
                            ", R=" + SelectedColor.R.ToString() +
                            ", G=" + SelectedColor.G.ToString() +
                            ", B=" + SelectedColor.B.ToString() + "]";
                    }

                    if (this.Enabled)
                    {
                        using (var brush = new SolidBrush(this.ForeColor))
                        {
                            g.DrawString(colorName, Font, brush, textRect, sf);
                        }
                    }
                    else
                    {
                        g.DrawString(colorName, Font, SystemBrushes.ControlDark, textRect, sf);
                    }
                }
            }
            #endregion
        }
        protected override void OnPaint(PaintEventArgs p)
        {
            var g = p.Graphics;

            #region Content
            var contentRect = new Rectangle(0, HeaderHeight, Width, Height - HeaderHeight - PanelDistance);

            if (BackgroundImage == null)
            {
                using (var brush = new SolidBrush(BackColor))
                {
                    g.FillRectangle(brush, contentRect.Left, contentRect.Top, contentRect.Width + 1, contentRect.Height + 1);
                }
            }
            else
            {
                StiControlPaint.DrawImageBackground(p.Graphics, BackgroundImage, contentRect);
            }

            if (DrawBorder)
            {
                g.DrawRectangle(BorderPen, 0, 0, Width - 1, Height - PanelDistance);
            }
            #endregion

            #region Header
            var headerRect = GetHeaderRect();
            var image      = !Collapsed ? upBitmap : downBitmap;

            Color textColor = Color.Black;

            #region Fill rectangle
            headerRect.Width++;
            headerRect.Height++;
            if (HeaderBackgroundImage == null)
            {
                if (Selected)
                {
                    if (isMouseOver)
                    {
                        using (var brush = new LinearGradientBrush(headerRect,
                                                                   StiColorUtils.Light(SelectedHeaderStartColor, 20),
                                                                   StiColorUtils.Light(SelectedHeaderEndColor, 20), 90))
                            g.FillRectangle(brush, headerRect);
                    }
                    else
                    {
                        using (var brush = new LinearGradientBrush(headerRect,
                                                                   SelectedHeaderStartColor,
                                                                   SelectedHeaderEndColor, 90))
                            g.FillRectangle(brush, headerRect);
                    }
                    textColor = SystemColors.ActiveCaptionText;
                }
                else
                {
                    if (isMouseOver)
                    {
                        using (var brush = new LinearGradientBrush(headerRect,
                                                                   StiColorUtils.Light(HeaderStartColor, 20),
                                                                   StiColorUtils.Light(HeaderEndColor, 20), 90))
                            g.FillRectangle(brush, headerRect);
                    }
                    else
                    {
                        using (var brush = new LinearGradientBrush(headerRect, HeaderStartColor, HeaderEndColor, 90))
                            g.FillRectangle(brush, headerRect);
                    }
                }
            }
            else
            {
                StiControlPaint.DrawImageBackground(p.Graphics, HeaderBackgroundImage, headerRect);
            }
            headerRect.Width--;
            headerRect.Height--;
            #endregion

            #region Draw button image
            if (image != null)
            {
                var imageRect = new Rectangle(headerRect.Width - 18, (headerRect.Height - 16) / 2, 16, 16);

                if (textColor != Color.Black && image != null)
                {
                    image = StiImageUtils.ReplaceImageColor((Bitmap)image, textColor, Color.Black);
                }
                g.DrawImage(image, imageRect);
            }
            #endregion

            #region Draw image
            int imageWidth = 0;
            if (Image != null)
            {
                var imageRect = new Rectangle(headerRect.X + 4,
                                              (headerRect.Height - Image.Size.Height) / 2, Image.Size.Width, Image.Size.Height);

                imageWidth = imageRect.Width + 2;

                g.DrawImage(Image, imageRect);
            }
            #endregion

            #region Draw header text
            var textRect = new Rectangle(5 + imageWidth, 0, headerRect.Width - 25 - imageWidth, headerRect.Height);

            if (textRect.Width > 0)
            {
                using (var sf = new StringFormat())
                {
                    sf.LineAlignment = StringAlignment.Center;
                    if (RightToLeft == RightToLeft.Yes)
                    {
                        sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }

                    sf.FormatFlags = StringFormatFlags.NoWrap;
                    sf.Trimming    = StringTrimming.EllipsisCharacter;

                    sf.HotkeyPrefix = HotkeyPrefix.Hide;

                    if (!TitleColor.IsEmpty)
                    {
                        textColor = TitleColor;
                    }
                    using (Brush brush = new SolidBrush(textColor))
                    {
                        g.DrawString(Text, TitleFont, brush, textRect, sf);
                    }
                }
            }
            #endregion

            if (DrawBorder)
            {
                g.DrawRectangle(BorderPen, headerRect);
            }
            #endregion
        }