コード例 #1
0
ファイル: MetroComboBox.cs プロジェクト: rajeshwarn/Creek
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            base.ItemHeight = GetPreferredSize(Size.Empty).Height;

            Color borderColor, foreColor;

            if (isHovered && !isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Hover(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Hover(Theme);
            }
            else if (isHovered && isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Press(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Press(Theme);
            }
            else if (!Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Disabled(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Disabled(Theme);
            }
            else
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Normal(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Normal(Theme);
            }

            using (var p = new Pen(borderColor))
            {
                var boxRect = new Rectangle(0, 0, Width - 1, Height - 1);
                e.Graphics.DrawRectangle(p, boxRect);
            }

            using (var b = new SolidBrush(foreColor))
            {
                e.Graphics.FillPolygon(b,
                                       new[]
                {
                    new Point(Width - 20, (Height / 2) - 2), new Point(Width - 9, (Height / 2) - 2),
                    new Point(Width - 15, (Height / 2) + 4)
                });
            }

            var textRect = new Rectangle(2, 2, Width - 20, Height - 4);

            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight),
                                  textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

            OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));

            if (displayFocusRectangle && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }

            if (drawPrompt)
            {
                DrawTextPrompt(e.Graphics);
            }
        }
コード例 #2
0
        public MetroComboBox()
        {
            SetStyle(ControlStyles.SupportsTransparentBackColor |
                     ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.ResizeRedraw |
                     ControlStyles.UserPaint, true);
            DropDownStyle = ComboBoxStyle.DropDownList;

            base.DrawMode = DrawMode.OwnerDrawFixed;

            drawPrompt = (SelectedIndex == -1);

            // setup the textbox
            this.SuspendLayout();
            textBox.Location      = new System.Drawing.Point(0, 0);
            textBox.FontSize      = (MetroTextBoxSize)metroComboBoxSize;
            textBox.FontWeight    = (MetroTextBoxWeight)metroComboBoxWeight;
            textBox.WaterMarkFont = MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight);
            textBox.Size          = this.Size;
            textBox.TabIndex      = 0;
            textBox.Margin        = new Padding(0);
            textBox.Padding       = new Padding(0);
            textBox.TextAlign     = HorizontalAlignment.Left;
            textBox.Resize       += TextBox_Resize;
            textBox.TextChanged  += TextBox_TextChanged;
            textBox.UseSelectable = true;
            textBox.Enter        += TextBox_Enter;
            textBox.Visible       = false;


            this.Controls.Add(textBox);
            this.ResumeLayout(true);
            this.AdjustControls();
        }
コード例 #3
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                Color foreColor;

                if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect) || e.State == DrawItemState.None)
                {
                    foreColor = MetroPaint.ForeColor.Link.Normal(Theme);
                }
                else
                {
                    using (SolidBrush b = new SolidBrush(MetroPaint.GetStyleColor(Style)))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }

                    foreColor = MetroPaint.ForeColor.Tile.Normal(Theme);
                }

                Rectangle textRect = new Rectangle(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
                TextRenderer.DrawText(e.Graphics, GetItemText(Items[e.Index]), MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
            }
            else
            {
                base.OnDrawItem(e);
            }
        }
コード例 #4
0
        private void DrawTextPrompt(Graphics g)
        {
            Color backColor = BackColor;

            if (!useCustomBackColor)
            {
                backColor = MetroPaint.BackColor.Form(Theme);
            }
            Rectangle textRect = new Rectangle(2, 2, Width - 20, Height - 4);

            TextRenderer.DrawText(g, promptText, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, SystemColors.GrayText, backColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
        }
コード例 #5
0
        private void DrawTextPrompt(Graphics g)
        {
            Color backColor = this.BackColor;

            if (!this.useCustomBackColor)
            {
                backColor = MetroPaint.BackColor.Form(this.Theme);
            }
            Rectangle rectangle = new Rectangle(2, 2, base.Width - 20, base.Height - 4);

            TextRenderer.DrawText(g, this.promptText, MetroFonts.ComboBox(this.metroComboBoxSize, this.metroComboBoxWeight), rectangle, SystemColors.GrayText, backColor, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter);
        }
コード例 #6
0
 public override System.Drawing.Size GetPreferredSize(System.Drawing.Size proposedSize)
 {
     System.Drawing.Size height;
     base.GetPreferredSize(proposedSize);
     using (Graphics graphic = base.CreateGraphics())
     {
         string str = (this.Text.Length > 0 ? this.Text : "MeasureText");
         proposedSize  = new System.Drawing.Size(2147483647, 2147483647);
         height        = TextRenderer.MeasureText(graphic, str, MetroFonts.ComboBox(this.metroComboBoxSize, this.metroComboBoxWeight), proposedSize, TextFormatFlags.VerticalCenter | TextFormatFlags.LeftAndRightPadding);
         height.Height = height.Height + 4;
     }
     return(height);
 }
コード例 #7
0
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            Color color;
            Color color1;

            base.ItemHeight = this.GetPreferredSize(System.Drawing.Size.Empty).Height;
            if (this.isHovered && !this.isPressed && base.Enabled)
            {
                color1 = MetroPaint.ForeColor.ComboBox.Hover(this.Theme);
                color  = MetroPaint.BorderColor.ComboBox.Hover(this.Theme);
            }
            else if (this.isHovered && this.isPressed && base.Enabled)
            {
                color1 = MetroPaint.ForeColor.ComboBox.Press(this.Theme);
                color  = MetroPaint.BorderColor.ComboBox.Press(this.Theme);
            }
            else if (base.Enabled)
            {
                color1 = MetroPaint.ForeColor.ComboBox.Normal(this.Theme);
                color  = MetroPaint.BorderColor.ComboBox.Normal(this.Theme);
            }
            else
            {
                color1 = MetroPaint.ForeColor.ComboBox.Disabled(this.Theme);
                color  = MetroPaint.BorderColor.ComboBox.Disabled(this.Theme);
            }
            using (Pen pen = new Pen(color))
            {
                Rectangle rectangle = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
                e.Graphics.DrawRectangle(pen, rectangle);
            }
            using (SolidBrush solidBrush = new SolidBrush(color1))
            {
                Graphics graphics = e.Graphics;
                Point[]  point    = new Point[] { new Point(base.Width - 20, base.Height / 2 - 2), new Point(base.Width - 9, base.Height / 2 - 2), new Point(base.Width - 15, base.Height / 2 + 4) };
                graphics.FillPolygon(solidBrush, point);
            }
            Rectangle rectangle1 = new Rectangle(2, 2, base.Width - 20, base.Height - 4);

            TextRenderer.DrawText(e.Graphics, this.Text, MetroFonts.ComboBox(this.metroComboBoxSize, this.metroComboBoxWeight), rectangle1, color1, TextFormatFlags.VerticalCenter);
            this.OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, color1, e.Graphics));
            if (this.displayFocusRectangle && this.isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, base.ClientRectangle);
            }
            if (this.drawPrompt)
            {
                this.DrawTextPrompt(e.Graphics);
            }
        }
コード例 #8
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                Color foreColor;
                Color backColor = BackColor;

                if (!UseCustomBackColor)
                {
                    backColor = MetroPaint.BackColor.Form(Theme);
                }

                if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect) || e.State == DrawItemState.None)
                {
                    using (SolidBrush b = new SolidBrush(backColor))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }

                    foreColor = MetroPaint.ForeColor.Link.Normal(Theme);
                }
                else
                {
                    using (SolidBrush b = new SolidBrush(MetroPaint.GetStyleColor(Style)))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }

                    foreColor = MetroPaint.ForeColor.Tile.Normal(Theme);
                }

                Rectangle textRect = new Rectangle(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
                TextRenderer.DrawText(e.Graphics, GetItemText(Items[e.Index]), MetroFonts.ComboBox(FontSize, FontWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

                var item = Items[e.Index] as ColorPickerComboxItem;
                if (item != null)
                {
                    var brush = new SolidBrush(item.DrawColor);
                    var rect  = e.Bounds;
                    var dr    = new Rectangle(rect.X + Width, rect.Y + rect.Height / 4, ColorWidth, rect.Height / 2);

                    e.Graphics.FillRectangle(brush, dr);
                    SelectedColor = item.DrawColor;
                }
            }
            else
            {
                base.OnDrawItem(e);
            }
        }
コード例 #9
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            Color color;

            if (e.Index < 0)
            {
                base.OnDrawItem(e);
                return;
            }
            Color backColor = this.BackColor;

            if (!this.useCustomBackColor)
            {
                backColor = MetroPaint.BackColor.Form(this.Theme);
            }
            if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect) || e.State == DrawItemState.None)
            {
                using (SolidBrush solidBrush = new SolidBrush(backColor))
                {
                    Graphics  graphics = e.Graphics;
                    int       left     = e.Bounds.Left;
                    int       top      = e.Bounds.Top;
                    int       width    = e.Bounds.Width;
                    Rectangle bounds   = e.Bounds;
                    graphics.FillRectangle(solidBrush, new Rectangle(left, top, width, bounds.Height));
                }
                color = MetroPaint.ForeColor.Link.Normal(this.Theme);
            }
            else
            {
                using (SolidBrush solidBrush1 = new SolidBrush(MetroPaint.GetStyleColor(this.Style)))
                {
                    Graphics  graphic   = e.Graphics;
                    int       num       = e.Bounds.Left;
                    int       top1      = e.Bounds.Top;
                    int       width1    = e.Bounds.Width;
                    Rectangle rectangle = e.Bounds;
                    graphic.FillRectangle(solidBrush1, new Rectangle(num, top1, width1, rectangle.Height));
                }
                color = MetroPaint.ForeColor.Tile.Normal(this.Theme);
            }
            int       num1       = e.Bounds.Top;
            int       width2     = e.Bounds.Width;
            Rectangle bounds1    = e.Bounds;
            Rectangle rectangle1 = new Rectangle(0, num1, width2, bounds1.Height);

            TextRenderer.DrawText(e.Graphics, base.GetItemText(base.Items[e.Index]), MetroFonts.ComboBox(this.metroComboBoxSize, this.metroComboBoxWeight), rectangle1, color, TextFormatFlags.VerticalCenter);
        }
コード例 #10
0
        public override Size GetPreferredSize(Size proposedSize)
        {
            Size preferredSize;

            base.GetPreferredSize(proposedSize);

            using (var g = CreateGraphics())
            {
                string measureText = Text.Length > 0 ? Text : "MeasureText";
                proposedSize          = new Size(int.MaxValue, int.MaxValue);
                preferredSize         = TextRenderer.MeasureText(g, measureText, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), proposedSize, TextFormatFlags.Left | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.VerticalCenter);
                preferredSize.Height += 4;
            }

            return(preferredSize);
        }
コード例 #11
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                Color foreColor = MetroPaint.ForeColor.Link.Normal(Theme);
                Color backColor = BackColor;

                if (!useCustomBackColor)
                {
                    backColor = MetroPaint.BackColor.Form(Theme);
                }

                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    using (SolidBrush b = new SolidBrush(MetroPaint.GetStyleColor(Style)))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }

                    foreColor = MetroPaint.ForeColor.Tile.Normal(Theme);
                    OnItemMouseHover(this.Items[e.Index], e);
                }
                else
                {
                    using (SolidBrush b = new SolidBrush(backColor))
                    {
                        e.Graphics.FillRectangle(b, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height));
                    }
                }

                if (this.DropDownStyle != ComboBoxStyle.DropDown)
                {
                    Rectangle textRect = new Rectangle(0, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
                    TextRenderer.DrawText(e.Graphics, GetItemText(Items[e.Index]), MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                }
                else
                {
                    Rectangle textRect = new Rectangle(0, e.Bounds.Top, this.textBox.Width, e.Bounds.Height);
                    TextRenderer.DrawText(e.Graphics, GetItemText(Items[e.Index]), MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);
                }
            }
            else
            {
                base.OnDrawItem(e);
            }
        }
コード例 #12
0
        private void DrawTextPrompt(Graphics g)
        {
            Rectangle textRect = new Rectangle(2, 2, Width - 20, Height - 4);

            TextRenderer.DrawText(g, promptText, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, SystemColors.GrayText, BackColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);
        }
コード例 #13
0
ファイル: MetroComboBox.cs プロジェクト: zz155666/QueryExcel
        protected virtual void OnPaintForeground(PaintEventArgs e)
        {
            base.ItemHeight = GetPreferredSize(Size.Empty).Height;

            Color borderColor, foreColor;

            if (isHovered && !isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Hover(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Hover(Theme);
            }
            else if (isHovered && isPressed && Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Press(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Press(Theme);
            }
            else if (!Enabled)
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Disabled(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Disabled(Theme);
            }
            else
            {
                foreColor   = MetroPaint.ForeColor.ComboBox.Normal(Theme);
                borderColor = MetroPaint.BorderColor.ComboBox.Normal(Theme);
            }

            using (Pen p = new Pen(borderColor))
            {
                int cornerRadius = 3;
                p.Width = 1;
                //边框工作区
                Rectangle    rect = this.ClientRectangle;
                GraphicsPath Rect = new GraphicsPath();
                // 添加圆弧
                Rect.AddArc(0, 0, cornerRadius * 2, cornerRadius * 2, 180, 90);
                Rect.AddArc(rect.Width - cornerRadius * 2 - 1, 0, cornerRadius * 2, cornerRadius * 2, 270, 90);
                Rect.AddArc(rect.Width - cornerRadius * 2 - 1, rect.Height - cornerRadius * 2 - 1, cornerRadius * 2,
                            cornerRadius * 2, 0, 90);
                Rect.AddArc(0, rect.Height - cornerRadius * 2 - 1, cornerRadius * 2, cornerRadius * 2, 90, 90);
                Rect.CloseFigure();
                e.Graphics.DrawPath(p, Rect);
            }

            using (SolidBrush b = new SolidBrush(foreColor))
            {
                e.Graphics.FillPolygon(b, new Point[] { new Point(Width - 20, (Height / 2) - 2), new Point(Width - 9, (Height / 2) - 2), new Point(Width - 15, (Height / 2) + 4) });
            }

            Rectangle textRect = new Rectangle(2, 2, Width - 20, Height - 4);

            TextRenderer.DrawText(e.Graphics, Text, MetroFonts.ComboBox(metroComboBoxSize, metroComboBoxWeight), textRect, foreColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter);

            OnCustomPaintForeground(new MetroPaintEventArgs(Color.Empty, foreColor, e.Graphics));

            if (displayFocusRectangle && isFocused)
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle);
            }

            if (drawPrompt)
            {
                DrawTextPrompt(e.Graphics);
            }
        }