Esempio n. 1
0
    /// <summary>
    /// Paints the control using the Buffered Paint API.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e)
    {
        if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled)
        {
            // draw in the vista/win7 style
            VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            Rectangle buttonBounds = ClientRectangle;
            buttonBounds.Inflate(1, 1);
            ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State));

            Rectangle clipBounds = _dropDownButtonBounds;
            clipBounds.Inflate(-2, -2);
            e.Graphics.SetClip(clipBounds);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);
        }
        else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported)
        {
            // draw using the visual style renderer
            ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState());
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
        }
        else
        {
            // draw using the legacy technique
            DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState());
        }

        OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds()));
    }
Esempio n. 2
0
    /// <summary>
    ///     Draws a combo box in the Windows Vista (and newer) style.
    /// </summary>
    /// <param name="graphics"></param>
    /// <param name="bounds"></param>
    /// <param name="state"></param>
    internal static void DrawComboBox(Graphics graphics, Rectangle bounds, ComboBoxState state)
    {
        var comboBounds = bounds;

        comboBounds.Inflate(1, 1);
        ButtonRenderer.DrawButton(graphics, comboBounds, GetPushButtonState(state));

        var buttonBounds = new Rectangle(
            bounds.Left + (bounds.Width - 17),
            bounds.Top,
            17,
            bounds.Height - (state != ComboBoxState.Pressed ? 1 : 0)
            );

        var buttonClip = buttonBounds;

        buttonClip.Inflate(-2, -2);

        using (var oldClip = graphics.Clip.Clone())
        {
            graphics.SetClip(buttonClip, CombineMode.Intersect);
            ComboBoxRenderer.DrawDropDownButton(graphics, buttonBounds, state);
            graphics.SetClip(oldClip, CombineMode.Replace);
        }
    }
Esempio n. 3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // Check if VisualStyles are supported...
            // Thanks to codeproject member: Mathiyazhagan for catching this. :)
            if (ComboBoxRenderer.IsSupported)
            {
                ComboBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(new Point(0, 0), fAnchorSize), GetState());
                ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(fAnchorSize.Width - 19, 2, 18, fAnchorSize.Height - 4), GetState());
            }
            else
            {
                ControlPaint.DrawComboButton(e.Graphics,
                                             new Rectangle(fAnchorSize.Width - 19, 2, 18, fAnchorSize.Height - 4),
                                             (Enabled) ? ButtonState.Normal : ButtonState.Inactive);
            }

            using (Brush b = new SolidBrush(BackColor))
            {
                e.Graphics.FillRectangle(b, AnchorClientBounds);
            }

            TextRenderer.DrawText(e.Graphics, fText, Font, AnchorClientBounds, ForeColor, TextFormatFlags.WordEllipsis);
        }
Esempio n. 4
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();

            //The dropDownRectangle defines position and size of dropdownbutton block,
            //the width is fixed to 17 and height to 16.
            //The dropdownbutton is aligned to right
            Rectangle dropDownRectangle =
                new Rectangle(ClientRectangle.Width - 20, 0, 20, ClientRectangle.Height);
            Brush         bkgBrush;
            ComboBoxState visualState;

            bkgBrush    = new SolidBrush(this.BackColor);
            visualState = ComboBoxState.Normal;
            // Painting...in action

            //Filling the background
            g.FillRectangle(bkgBrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);

            //Drawing the border
            g.DrawRectangle(Pens.Gray, 0, 0, this.ClientSize.Width - 1, this.ClientSize.Height - 1);

            //Drawing the datetime text
            g.DrawString(this.Text, this.Font, Brushes.Black, 0, 2);

            //Drawing the dropdownbutton using ComboBoxRenderer
            ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, visualState);

            g.Dispose();
            bkgBrush.Dispose();
        }
Esempio n. 5
0
        private void DrawButton(Graphics g, ComboBoxState state)
        {
            if ((ComboBoxRenderer.IsSupported) & (Application.RenderWithVisualStyles))
            {
                ComboBoxRenderer.DrawDropDownButton(g, buttonRect, state);
            }
            else
            {
                ButtonState btnState = ButtonState.Normal;
                switch (state)
                {
                case ComboBoxState.Hot:
                    btnState = ButtonState.Normal;
                    break;

                case ComboBoxState.Normal:
                    btnState = ButtonState.Normal;
                    break;

                case ComboBoxState.Disabled:
                    btnState = ButtonState.Inactive;
                    break;

                case ComboBoxState.Pressed:
                    btnState = ButtonState.Flat;
                    break;
                }
                ControlPaint.DrawComboButton(g, buttonRect, btnState);
            }
        }
Esempio n. 6
0
        // Draw the combo box in the current state.
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (!ComboBoxRenderer.IsSupported)
            {
                this.Parent.Text = "Visual Styles Disabled";
                return;
            }

            this.Parent.Text = "CustomComboBox Enabled";

            // Always draw the main text box and drop down arrow in their
            // current states
            ComboBoxRenderer.DrawTextBox(e.Graphics, topTextBoxRectangle,
                                         this.Text, this.Font, textBoxState);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, arrowRectangle,
                                                arrowState);

            // Only draw the bottom text box if the arrow has been clicked
            if (isActivated)
            {
                ComboBoxRenderer.DrawTextBox(e.Graphics,
                                             bottomTextBoxRectangle, bottomText, this.Font,
                                             textBoxState);
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            //Check if VisualStyles are supported...
            //Thanks to codeproject member: Mathiyazhagan for catching this. :)
            if (ComboBoxRenderer.IsSupported && TextBoxRenderer.IsSupported)
            {
                TextFormatFlags flag = TextFormatFlags.TextBoxControl | TextFormatFlags.SingleLine;

                Rectangle textRect = new Rectangle(new Point(2, 2), _AnchorSize);
                TextBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(new Point(0, 0), _AnchorSize), this.Text, this.Font, textRect, System.Windows.Forms.VisualStyles.TextBoxState.Normal);
                //TextBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(new Point(0, 0), _AnchorSize), this.Text, this.Font, textRect, flag, getState());
                ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(_AnchorSize.Width - 19, 2, 18, _AnchorSize.Height - 4), getState());
            }
            else
            {
                ControlPaint.DrawComboButton(e.Graphics, new Rectangle(
                                                 _AnchorSize.Width - 19, 2, 18, _AnchorSize.Height - 4),
                                             (this.Enabled) ? System.Windows.Forms.ButtonState.Normal : System.Windows.Forms.ButtonState.Inactive);
            }

            using (Brush b = new SolidBrush(this.BackColor))
            {
                e.Graphics.FillRectangle(b, this.AnchorClientBounds);
            }
            Rectangle rect = new Rectangle(0, 0, this.AnchorClientBounds.Width, this.AnchorClientBounds.Height - 2);

            TextRenderer.DrawText(e.Graphics, this.Text, this.Font, rect, this.ForeColor, TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter);
        }
Esempio n. 8
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), ClientRectangle, new StringFormat
            {
                // Alignment = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            });

            // Render the dropdown button: shrink button area by one px
            var rect = new Rectangle(ClientRectangle.Left + ClientRectangle.Width - 19, ClientRectangle.Top + 1,
                                     19, ClientRectangle.Height - 2);

            if (ComboBoxRenderer.IsSupported)
            {
                var bstate = this.Enabled ? ComboBoxState.Normal : ComboBoxState.Disabled;
                ComboBoxRenderer.DrawDropDownButton(e.Graphics, rect, bstate);
            }
            else
            {
                var bstate = this.Enabled ? ButtonState.Flat : ButtonState.Inactive;
                ControlPaint.DrawComboButton(e.Graphics, rect, bstate);
            }
            ControlPaint.DrawBorder(e.Graphics, DisplayRectangle, Color.Gray, ButtonBorderStyle.Solid);
            base.OnPaint(e);
        }
Esempio n. 9
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (Application.RenderWithVisualStyles & useComboBoxTheme)
            {
                ComboBoxState cbState = ComboBoxState.Normal;

                if (base.MouseIsDown)
                {
                    cbState = ComboBoxState.Pressed;
                }
                else if (base.MouseIsOver)
                {
                    cbState = ComboBoxState.Hot;
                }

                Rectangle dropDownButtonRect = new Rectangle(0, 0, Width, Height);
                if (cbState == ComboBoxState.Normal)
                {
                    pevent.Graphics.FillRectangle(SystemBrushes.Window, dropDownButtonRect);
                }
                ComboBoxRenderer.DrawDropDownButton(pevent.Graphics, dropDownButtonRect, cbState);
            }
        }
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            switch (this.lTipCelula)
            {
            case EnumTipCelula.Vid:
                break;

            case EnumTipCelula.Text:
                break;

            case EnumTipCelula.Lista:
                ComboBoxRenderer.DrawDropDownButton(graphics, clipBounds, System.Windows.Forms.VisualStyles.ComboBoxState.Normal);
                break;

            case EnumTipCelula.Bifa:
                System.Windows.Forms.VisualStyles.CheckBoxState StareBifa = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal;
                if (this.Value != null && Convert.ToBoolean(this.Value))
                {
                    StareBifa = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal;
                }
                CheckBoxRenderer.DrawCheckBox(graphics, clipBounds.Location, StareBifa);
                break;

            case EnumTipCelula.Buton:
                break;

            default:
                break;
            }
        }
Esempio n. 11
0
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds,
                                      Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates dataGridViewElementState,
                                      object value,
                                      object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds,
                       cellBounds, rowIndex,
                       dataGridViewElementState, value,
                       formattedValue, errorText,
                       cellStyle, advancedBorderStyle, paintParts);

            int width = 20; // 20 px

            buttonRect   = new Rectangle(cellBounds.X + cellBounds.Width - width, cellBounds.Y + 2, width, cellBounds.Height - 3);
            cellLocation = cellBounds.Location;
            if (ComboBoxRenderer.IsSupported)
            {
                ComboBoxRenderer.DrawDropDownButton(graphics, buttonRect, currentState);
            }
            else
            {
                graphics.DrawImage(Properties.Resources.downarrow, buttonRect);
            }
        }
    /// <summary>
    /// Draws a drop-down glyph in the specified bounds.
    /// </summary>
    /// <param name="g"></param>
    /// <param name="bounds"></param>
    /// <param name="state"></param>
    /// <param name="color"></param>
    static void DrawDropDownGlyph(Graphics g, Rectangle bounds, ComboBoxState state, Color?color = null)
    {
        if (state != ComboBoxState.Normal)
        {
            // standard dropdown button
            ComboBoxRenderer.DrawDropDownButton(g, bounds, state);
        }
        else if (Environment.OSVersion.Version >= new Version(10, 0))
        {
            // windows 10 uses a slightly different chevron glyph
            int mX = bounds.X + (bounds.Width / 2);
            int mY = bounds.Y + (bounds.Height / 2);

            using (Pen pen = new Pen(color ?? Color.FromArgb(66, 66, 66), 1)) {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                g.DrawLine(pen, mX - 4, mY - 2, mX - 1, mY + 1);
                g.DrawLine(pen, mX + 3, mY - 2, mX - 1, mY + 1);

                g.DrawLine(pen, mX - 4, mY - 3, mX, mY + 1);
                g.DrawLine(pen, mX + 3, mY - 3, mX, mY + 1);
            }
        }
        else if (Environment.OSVersion.Version >= new Version(6, 2))
        {
            // windows 8 uses a chevron glyph
            int mX = bounds.X + (bounds.Width / 2);
            int mY = bounds.Y + (bounds.Height / 2);
            using (System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath()) {
                path.AddLine(mX - 3, mY - 2, mX - 3, mY - 1);
                path.AddLine(mX - 3, mY - 1, mX, mY + 2);
                path.AddLine(mX, mY + 2, mX + 3, mY - 1);
                path.AddLine(mX + 3, mY - 1, mX + 3, mY - 2);

                using (Pen pen = new Pen(color ?? Color.FromArgb(66, 66, 66), 2)) {
                    pen.StartCap = System.Drawing.Drawing2D.LineCap.Flat;
                    pen.EndCap   = System.Drawing.Drawing2D.LineCap.Flat;

                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.SetClip(new Rectangle(mX - 3, mY - 2, 7, 6));
                    g.DrawPath(pen, path);
                    g.ResetClip();
                }
            }
        }
        else
        {
            // windows vista and 7 use a triangle glyph
            g.FillPolygon(Brushes.Black, new Point[] {
                new Point(bounds.X + (bounds.Width / 2) - 3, bounds.Y + (bounds.Height / 2) - 1),
                new Point(bounds.X + (bounds.Width / 2) + 4, bounds.Y + (bounds.Height / 2) - 1),
                new Point(bounds.X + (bounds.Width / 2), bounds.Y + (bounds.Height / 2) + 3)
            });
        }
    }
Esempio n. 13
0
        public void OnPaint()
        {
            Rectangle rect = this.ClientRectangle;
            Graphics  g    = this.CreateGraphics();

            //Draw border
            if (Application.RenderWithVisualStyles)
            {
                TextBoxRenderer.DrawTextBox(g, rect, TextBoxState.Normal);
            }
            else
            {
                ControlPaint.DrawBorder3D(g, rect, Border3DStyle.Sunken, Border3DSide.All);
            }

            // Reduce rectangle by borderSize
            rect.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height);

            Rectangle rectButton = getButtonRect();

            if (Application.RenderWithVisualStyles)
            {
                if (m_bReadOnly || !Enabled)
                {
                    //Fill background
                    g.FillRectangle(new SolidBrush(this.BackColor), rect);
                    ComboBoxRenderer.DrawDropDownButton(g, rectButton, ComboBoxState.Disabled);
                }
                else
                {
                    //Fill background
                    g.FillRectangle(new SolidBrush(Color.White), rect);
                    ComboBoxRenderer.DrawDropDownButton(g, rectButton, ComboBoxState.Normal);
                }
            }
            else
            {
                if (m_bReadOnly || !Enabled)
                {
                    //Fill background
                    g.FillRectangle(new SolidBrush(this.BackColor), rect);
                    ControlPaint.DrawComboButton(g, rectButton, ButtonState.Inactive);
                }
                else
                {
                    //Fill background
                    g.FillRectangle(new SolidBrush(Color.White), rect);
                    ControlPaint.DrawComboButton(g, rectButton, ButtonState.Normal);
                }
            }


            g.Dispose();
        }
Esempio n. 14
0
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     //draw a drop down button
     if ((cellState & DataGridViewElementStates.Selected) != 0)
     {
         var cb = cellBounds;
         var r  = new Rectangle(cb.Right - cb.Height, cb.Top, cb.Height, cb.Height);
         //ComboBoxRenderer.DrawTextBox(graphics, cb, formattedValue as string, this.Style.Font ?? DataGridView.Font, ComboBoxState.Normal);
         ComboBoxRenderer.DrawDropDownButton(graphics, r, ComboBoxState.Normal);
     }
 }
        protected virtual void DrawArrow(PaintEventArgs pe)
        {
            ComboBoxState arrowState = this.Enabled ? this.ArrowState : ComboBoxState.Disabled;

            if (ComboBoxRenderer.IsSupported && Application.RenderWithVisualStyles)
            {
                ComboBoxRenderer.DrawDropDownButton(pe.Graphics, this.ArrowBounds, arrowState);
            }
            else
            {
                ControlPaint.DrawComboButton(pe.Graphics, this.ArrowBounds,
                                             ComboBoxStateToComboButtonState(arrowState));
            }
        }
Esempio n. 16
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);


            Rectangle Rectangle1 = this.DataGridView.GetCellDisplayRectangle(this.ColumnIndex, -1, false);

            int       y          = 3;
            Rectangle Rectangle2 = new Rectangle(Rectangle1.Right - 40, y, Rectangle1.Height - 2 * y, Rectangle1.Height - 2 * y);

            //ButtonRenderer.DrawButton(graphics, Rectangle2,"滤",new Font("微软雅黑",8),false, PushButtonState.Default);

            ComboBoxRenderer.DrawDropDownButton(graphics, Rectangle2, ComboBoxState.Normal);
        }
Esempio n. 17
0
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     if (this.FilteringEnabled && ((paintParts & DataGridViewPaintParts.ContentBackground) != DataGridViewPaintParts.None))
     {
         Rectangle dropDownButtonBounds = this.DropDownButtonBounds;
         if ((dropDownButtonBounds.Width >= 1) && (dropDownButtonBounds.Height >= 1))
         {
             if (Application.RenderWithVisualStyles)
             {
                 ComboBoxState normal = ComboBoxState.Normal;
                 if (this.dropDownListBoxShowing)
                 {
                     normal = ComboBoxState.Pressed;
                 }
                 else if (this.filtered)
                 {
                     normal = ComboBoxState.Hot;
                 }
                 ComboBoxRenderer.DrawDropDownButton(graphics, dropDownButtonBounds, normal);
             }
             else
             {
                 Point[]         pointArray;
                 Point[]         pointArray2;
                 int             num   = 0;
                 PushButtonState state = PushButtonState.Normal;
                 if (this.dropDownListBoxShowing)
                 {
                     state = PushButtonState.Pressed;
                     num   = 1;
                 }
                 ButtonRenderer.DrawButton(graphics, dropDownButtonBounds, state);
                 if (this.filtered)
                 {
                     pointArray2 = new Point[] { new Point((((dropDownButtonBounds.Width / 2) + dropDownButtonBounds.Left) - 1) + num, ((((dropDownButtonBounds.Height * 3) / 4) + dropDownButtonBounds.Top) - 1) + num), new Point(((dropDownButtonBounds.Width / 4) + dropDownButtonBounds.Left) + num, (((dropDownButtonBounds.Height / 2) + dropDownButtonBounds.Top) - 1) + num), new Point(((((dropDownButtonBounds.Width * 3) / 4) + dropDownButtonBounds.Left) - 1) + num, (((dropDownButtonBounds.Height / 2) + dropDownButtonBounds.Top) - 1) + num) };
                     pointArray  = pointArray2;
                     graphics.DrawPolygon(SystemPens.ControlText, pointArray);
                 }
                 else
                 {
                     pointArray2 = new Point[] { new Point((((dropDownButtonBounds.Width / 2) + dropDownButtonBounds.Left) - 1) + num, ((((dropDownButtonBounds.Height * 3) / 4) + dropDownButtonBounds.Top) - 1) + num), new Point(((dropDownButtonBounds.Width / 4) + dropDownButtonBounds.Left) + num, (((dropDownButtonBounds.Height / 2) + dropDownButtonBounds.Top) - 1) + num), new Point(((((dropDownButtonBounds.Width * 3) / 4) + dropDownButtonBounds.Left) - 1) + num, (((dropDownButtonBounds.Height / 2) + dropDownButtonBounds.Top) - 1) + num) };
                     pointArray  = pointArray2;
                     graphics.FillPolygon(SystemBrushes.ControlText, pointArray);
                 }
             }
         }
     }
 }
Esempio n. 18
0
        //<Snippet10>
        // Render the drop-down arrow with or without visual styles.
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (!ComboBoxRenderer.IsSupported)
            {
                ControlPaint.DrawComboButton(e.Graphics,
                                             this.ClientRectangle, ButtonState.Normal);
            }
            else
            {
                ComboBoxRenderer.DrawDropDownButton(e.Graphics,
                                                    this.ClientRectangle, ComboBoxState.Normal);
            }
        }
Esempio n. 19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Color textColor = Color.Red;

            if (this.Focused)
            {
                textColor = SystemColors.HighlightText;
            }

            e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), ClientRectangle, new StringFormat
            {
                Alignment     = StringAlignment.Center,
                LineAlignment = StringAlignment.Center
            });
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, buttonRectangle, btnvisualState);
        }
Esempio n. 20
0
 /// <summary>
 /// This member overrides <see cref="Control.OnPaint">Control.OnPaint</see>.
 /// </summary>
 protected override void OnPaint(PaintEventArgs pe)
 {
     if (Application.RenderWithVisualStyles)
     {
         ComboBoxRenderer.DrawDropDownButton(
             pe.Graphics,
             ClientRectangle,
             !Enabled ? ComboBoxState.Disabled : (pushed ? ComboBoxState.Pressed : ((hover || Focused) ? ComboBoxState.Hot : ComboBoxState.Normal)));
     }
     else
     {
         ControlPaint.DrawComboButton(
             pe.Graphics,
             ClientRectangle,
             !Enabled ? ButtonState.Inactive : (pushed ? ButtonState.Pushed : ((hover || Focused) ? ButtonState.Normal : ButtonState.Normal)));
     }
 }
Esempio n. 21
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            //Graphics g = e.Graphics;

            //The dropDownRectangle defines position and size of dropdownbutton block,
            //the width is fixed to 17 and height to 16. The dropdownbutton is aligned to right
            Rectangle     dropDownRectangle = new Rectangle(ClientRectangle.Width - 17, 0, 17, 16);
            Brush         bkgBrush;
            ComboBoxState visualState;

            //When the control is enabled the brush is set to Backcolor,
            //otherwise to color stored in _backDisabledColor
            if (this.Enabled)
            {
                bkgBrush    = new SolidBrush(this.BackColor);
                visualState = ComboBoxState.Normal;
            }
            else
            {
                bkgBrush    = new SolidBrush(this._backDisabledColor);
                visualState = ComboBoxState.Disabled;
            }

            // Painting...in action

            //Filling the background
            g.FillRectangle(bkgBrush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);

            //Drawing the datetime text
            g.DrawString(this.Text, this.Font, Brushes.Black, 0, 2);

            //Drawing the dropdownbutton using ComboBoxRenderer
            if (ComboBoxRenderer.IsSupported)
            {
                ComboBoxRenderer.DrawDropDownButton(g, dropDownRectangle, visualState);
            }
            else
            {
                ControlPaint.DrawComboButton(g, dropDownRectangle, (this.Enabled) ? ButtonState.Normal : ButtonState.Inactive);
            }

            g.Dispose();
            bkgBrush.Dispose();
        }
 protected virtual void DrawFrame(PaintEventArgs pe)
 {
     if (ComboBoxRenderer.IsSupported && Application.RenderWithVisualStyles)
     {
         ComboBoxRenderer.DrawTextBox(pe.Graphics, frameBounds,
                                      this.Enabled ? ComboBoxState.Normal : ComboBoxState.Disabled);
     }
     else
     {
         ControlPaint.DrawButton(pe.Graphics, frameBounds, ButtonState.Pushed);
     }
     if (this.Enabled)
     {
         using (SolidBrush brush = new SolidBrush(this.BackColor)) {
             pe.Graphics.FillRectangle(brush, this.childBounds);
         }
     }
 }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs pevent)
        {
            ComboBoxState state = State;

            base.OnPaint(pevent);
            const int xsize = 17;
            //const int ysize = 19;
            int ysize = this.Height - 2;

            if (ComboBoxRenderer.IsSupported)
            {
                ComboBoxRenderer.DrawDropDownButton(pevent.Graphics, new Rectangle(this.Width - xsize - 1, this.Height - ysize - 1, xsize, ysize), state);
            }
            else
            {
                ControlPaint.DrawComboButton(pevent.Graphics, new Rectangle(this.Width - xsize - 1, this.Height - ysize - 1, xsize, ysize), (this.Enabled) ? ButtonState.Normal : ButtonState.Inactive);
            }
        }
Esempio n. 24
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (Application.RenderWithVisualStyles & _useComboBoxTheme)
            {
                ComboBoxState state = ComboBoxState.Normal;

                if (MouseIsDown)
                {
                    state = ComboBoxState.Pressed;
                }
                else if (MouseIsOver)
                {
                    state = ComboBoxState.Hot;
                }

                Rectangle dropDownButtonRect = new Rectangle(0, 0, Width, Height);
                if (state == ComboBoxState.Normal)
                {
                    pevent.Graphics.FillRectangle(SystemBrushes.Window, dropDownButtonRect);
                }

                using (var hdc = new DeviceContextHdcScope(pevent))
                {
                    ComboBoxRenderer.DrawDropDownButtonForHandle(
                        hdc,
                        dropDownButtonRect,
                        state,
                        DpiHelper.IsScalingRequirementMet ? HandleInternal : IntPtr.Zero);
                }

                // Redraw focus cues.
                //
                // For consistency with other PropertyGrid buttons, i.e. those opening system dialogs ("..."), that
                // always show visual cues when focused, we need to do the same for this custom button, painted as
                // a ComboBox control part (drop-down).
                if (Focused)
                {
                    dropDownButtonRect.Inflate(-1, -1);
                    ControlPaint.DrawFocusRectangle(pevent.Graphics, dropDownButtonRect, ForeColor, BackColor);
                }
            }
        }
    /// <summary>
    /// Paints the control using the Buffered Paint API.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    void bufferedPainter_PaintVisualState(object sender, BufferedPaintEventArgs <ComboBoxState> e)
    {
        if (_drawWithVisualStyles && _bufferedPainter.BufferedPaintSupported && _bufferedPainter.Enabled && (_style == DropDownControlStyles.Discrete))
        {
            // draw in the vista/win7 style
            VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Normal);
            r.DrawParentBackground(e.Graphics, ClientRectangle, this);

            Rectangle buttonBounds = ClientRectangle;
            buttonBounds.Inflate(1, 1);
            ButtonRenderer.DrawButton(e.Graphics, buttonBounds, GetPushButtonState(e.State));

            Rectangle clipBounds = _dropDownButtonBounds;
            clipBounds.Inflate(-2, -2);
            e.Graphics.SetClip(clipBounds);
            ComboBoxRenderer.DrawDropDownButton(e.Graphics, _dropDownButtonBounds, e.State);
            e.Graphics.SetClip(ClientRectangle);
        }
        else if (_drawWithVisualStyles && ComboBoxRenderer.IsSupported)
        {
            // draw using the visual style renderer
            if (Enabled)
            {
                ComboBoxRenderer.DrawTextBox(e.Graphics, ClientRectangle, GetTextBoxState());
            }
            else
            {
                Rectangle outline = ClientRectangle;
                outline.Width--;
                outline.Height--;
                e.Graphics.FillRectangle(SystemBrushes.Control, ClientRectangle);
                e.Graphics.DrawRectangle(Pens.LightGray, outline);
            }

            DrawDropDownGlyph(e.Graphics, _dropDownButtonBounds, e.State);
        }
        else
        {
            // draw using the legacy technique
            DrawLegacyComboBox(e.Graphics, ClientRectangle, _dropDownButtonBounds, BackColor, GetPlainButtonState());
        }

        OnPaintContent(new DropDownPaintEventArgs(e.Graphics, ClientRectangle, GetTextBoxBounds()));
    }
Esempio n. 26
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            base.OnPaint(pevent);

            if (Application.RenderWithVisualStyles & useComboBoxTheme)
            {
                ComboBoxState cbState = ComboBoxState.Normal;

                if (base.MouseIsDown)
                {
                    cbState = ComboBoxState.Pressed;
                }
                else if (base.MouseIsOver)
                {
                    cbState = ComboBoxState.Hot;
                }

                Rectangle dropDownButtonRect = new Rectangle(0, 0, Width, Height);
                if (cbState == ComboBoxState.Normal)
                {
                    pevent.Graphics.FillRectangle(SystemBrushes.Window, dropDownButtonRect);
                }
                if (!DpiHelper.EnableDpiChangedHighDpiImprovements)
                {
                    ComboBoxRenderer.DrawDropDownButton(pevent.Graphics, dropDownButtonRect, cbState);
                }
                else
                {
                    ComboBoxRenderer.DrawDropDownButtonForHandle(pevent.Graphics, dropDownButtonRect, cbState, this.HandleInternal);
                }

                if (AccessibilityImprovements.Level1)
                {
                    // Redraw focus cues
                    // For consistency with other PropertyGrid buttons, i.e. those opening system dialogs ("..."), that always show visual cues when focused,
                    // we need to do the same for this custom button, painted as ComboBox control part (drop-down).
                    if (Focused)
                    {
                        dropDownButtonRect.Inflate(-1, -1);
                        ControlPaint.DrawFocusRectangle(pevent.Graphics, dropDownButtonRect, ForeColor, BackColor);
                    }
                }
            }
        }
Esempio n. 27
0
        protected override void OnPaint(PaintEventArgs pevent)
        {
            var state = State;

            base.OnPaint(pevent);
            const int xsize = 17;
            //const int ysize = 19;
            var ysize = Height - 2;

            if (ComboBoxRenderer.IsSupported)
            {
                ComboBoxRenderer.DrawDropDownButton(pevent.Graphics, new Rectangle(Width - xsize - 1, Height - ysize - 1, xsize, ysize), state);
            }
            else
            {
                ControlPaint.DrawComboButton(pevent.Graphics, new Rectangle(Width - xsize - 1, Height - ysize - 1, xsize, ysize),
                                             Enabled ? ButtonState.Normal : ButtonState.Inactive);
            }
        }
Esempio n. 28
0
        private void PaintArrow(Graphics g)
        {
            var bounds = ClientRectangle;

            var buttonBounds = new Rectangle(
                bounds.Left + (bounds.Width - 19),
                bounds.Top + 2,
                17,
                bounds.Height - (State != PushButtonState.Pressed ? 1 : 0) - 2
                );

            var buttonClip = buttonBounds;

            buttonClip.Inflate(-2, -2);

            using (var oldClip = g.Clip.Clone())
            {
                g.SetClip(buttonClip, CombineMode.Intersect);
                try
                {
                    ComboBoxRenderer.DrawDropDownButton(g, buttonBounds, GetSt(State));
                }
                catch
                {
                    // ignored
                }

                g.SetClip(oldClip, CombineMode.Replace);
            }


            /*  Point middle = new Point(Convert.ToInt32(dropDownRect.Left + dropDownRect.Width / 2), Convert.ToInt32(dropDownRect.Top + dropDownRect.Height / 2));
             *
             * //if the width is odd - favor pushing it over one pixel right.
             * middle.X += (dropDownRect.Width % 2);
             *
             * Point[] arrow = new[] { new Point(middle.X - 2, middle.Y - 1), new Point(middle.X + 3, middle.Y - 1), new Point(middle.X, middle.Y + 2) };
             *
             * if (Enabled)
             *  g.FillPolygon(SystemBrushes.ControlText, arrow);
             * else
             *  g.FillPolygon(SystemBrushes.ButtonShadow, arrow);*/
        }
Esempio n. 29
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (!_showDropDownButton)
            {
                return;
            }

            var Rectangle = new Rectangle(ClientRectangle.Width - _buttonWidth, 0, _buttonWidth, ClientRectangle.Height);

            if (ComboBoxRenderer.IsSupported)
            {
                ComboBoxRenderer.DrawDropDownButton(e.Graphics, Rectangle, GetState());
            }
            else
            {
                ControlPaint.DrawComboButton(e.Graphics, Rectangle, (this.Enabled) ? ButtonState.Normal : ButtonState.Inactive);
            }
        }
        public override void Paint(PropertyGrid grid, PropertyGrid.Item item, Graphics g, Rectangle rect)
        {
            if (base.Editing == item)
            {
                ComboBoxState comboBoxState = ComboBoxState.Normal;
                switch (this.mState)
                {
                case PushButtonState.Hot:
                {
                    comboBoxState = ComboBoxState.Hot;
                    break;
                }

                case PushButtonState.Pressed:
                {
                    comboBoxState = ComboBoxState.Pressed;
                    break;
                }

                case PushButtonState.Disabled:
                {
                    comboBoxState = ComboBoxState.Disabled;
                    break;
                }
                }
                rect.X     = this.mButton.X;
                rect.Width = this.mButton.Width;
                if (!Application.RenderWithVisualStyles)
                {
                    ControlPaint.DrawScrollButton(g, rect, ScrollButton.Down, (comboBoxState == ComboBoxState.Pressed ? ButtonState.Pushed : ButtonState.Normal));
                }
                else
                {
                    ComboBoxRenderer.DrawDropDownButton(g, rect, comboBoxState);
                }
            }
            else
            {
                base.Paint(grid, item, g, rect);
            }
        }