示例#1
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);
            }
        }
示例#2
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));
        }
        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);
                    }
            }
        }
        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
        }