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);
                    }
            }
        }
Example #2
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);
            }
        }
Example #3
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);
                }
            }
        }