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);
            }
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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);
                }
            }
        }
        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);
                    }
            }
        }
Esempio n. 5
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);
            }
        }