/// <include file='doc\CheckBoxRenderer.uex' path='docs/doc[@for="CheckBoxRenderer.DrawCheckBox3"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Renders a CheckBox control.
        ///    </para>
        /// </devdoc>
        public static void DrawCheckBox(Graphics g, Point glyphLocation, Rectangle textBounds, string checkBoxText, Font font, TextFormatFlags flags, bool focused, CheckBoxState state)
        {
            Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));
            Color     textColor;

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                visualStyleRenderer.DrawBackground(g, glyphBounds);
                textColor = visualStyleRenderer.GetColor(ColorProperty.TextColor);
            }
            else
            {
                if (IsMixed(state))
                {
                    ControlPaint.DrawMixedCheckBox(g, glyphBounds, ConvertToButtonState(state));
                }
                else
                {
                    ControlPaint.DrawCheckBox(g, glyphBounds, ConvertToButtonState(state));
                }

                textColor = SystemColors.ControlText;
            }

            TextRenderer.DrawText(g, checkBoxText, font, textBounds, textColor, flags);

            if (focused)
            {
                ControlPaint.DrawFocusRectangle(g, textBounds);
            }
        }
Example #2
0
        void DrawCheckBox(PaintEventArgs e, LayoutData layout)
        {
            Graphics g        = e.Graphics;
            Region   original = g.Clip;

            ButtonState style = (ButtonState)0;

            if (CheckState == CheckState.Unchecked)
            {
                style |= ButtonState.Normal;
            }
            else
            {
                style |= ButtonState.Checked;
            }

            if (!Enabled)
            {
                style |= ButtonState.Inactive;
            }

            if (base.MouseIsDown)
            {
                style |= ButtonState.Pushed;
            }

            if (CheckState == CheckState.Indeterminate)
            {
                ControlPaint.DrawMixedCheckBox(g, layout.checkBounds, style);
            }
            else
            {
                ControlPaint.DrawCheckBox(g, layout.checkBounds, style);
            }
        }
Example #3
0
        /// <include file='doc\DataGridBoolColumn.uex' path='docs/doc[@for="DataGridBoolColumn.Paint2"]/*' />
        /// <devdoc>
        /// <para>Draws the <see cref='System.Windows.Forms.DataGridBoolColumn'/> with the given <see cref='System.Drawing.Graphics'/>, <see cref='System.Drawing.Rectangle'/>,
        ///    row number, <see cref='System.Drawing.Brush'/>, and <see cref='System.Drawing.Color'/>. </para>
        /// </devdoc>
        protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum,
                                               Brush backBrush, Brush foreBrush,
                                               bool alignToRight)
        {
            object      value        = (isEditing && editingRow == rowNum) ? currentValue : GetColumnValueAtRow(source, rowNum);
            ButtonState checkedState = ButtonState.Inactive;

            if (!Convert.IsDBNull(value))
            {
                checkedState = ((bool)value ? ButtonState.Checked : ButtonState.Normal);
            }

            Rectangle box = GetCheckBoxBounds(bounds, alignToRight);

            Region r = g.Clip;

            g.ExcludeClip(box);

            System.Drawing.Brush selectionBrush = this.DataGridTableStyle.IsDefault ? this.DataGridTableStyle.DataGrid.SelectionBackBrush : this.DataGridTableStyle.SelectionBackBrush;
            if (isSelected && editingRow == rowNum && !IsReadOnly())
            {
                g.FillRectangle(selectionBrush, bounds);
            }
            else
            {
                g.FillRectangle(backBrush, bounds);
            }
            g.Clip = r;

            if (checkedState == ButtonState.Inactive)
            {
                ControlPaint.DrawMixedCheckBox(g, box, ButtonState.Checked);
            }
            else
            {
                ControlPaint.DrawCheckBox(g, box, checkedState);
            }

            // if the column is read only we should still show selection
            if (IsReadOnly() && isSelected && source.Position == rowNum)
            {
                bounds.Inflate(-1, -1);
                System.Drawing.Pen pen = new System.Drawing.Pen(selectionBrush);
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                g.DrawRectangle(pen, bounds);
                pen.Dispose();
                // restore the bounds rectangle
                bounds.Inflate(1, 1);
            }
        }
Example #4
0
        public static void DrawCheckBox(Graphics g, Point glyphLocation, CheckBoxState state)
        {
            Rectangle bounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);
                visualStyleRenderer.DrawBackground(g, bounds);
            }
            else if (IsMixed(state))
            {
                ControlPaint.DrawMixedCheckBox(g, bounds, ConvertToButtonState(state));
            }
            else
            {
                ControlPaint.DrawCheckBox(g, bounds, ConvertToButtonState(state));
            }
        }
Example #5
0
        protected internal override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight)
        {
            object      obj2     = (this.isEditing && (this.editingRow == rowNum)) ? this.currentValue : this.GetColumnValueAtRow(source, rowNum);
            ButtonState inactive = ButtonState.Inactive;

            if (!Convert.IsDBNull(obj2))
            {
                inactive = ((bool)obj2) ? ButtonState.Checked : ButtonState.Normal;
            }
            Rectangle checkBoxBounds = this.GetCheckBoxBounds(bounds, alignToRight);
            Region    clip           = g.Clip;

            g.ExcludeClip(checkBoxBounds);
            Brush brush = this.DataGridTableStyle.IsDefault ? this.DataGridTableStyle.DataGrid.SelectionBackBrush : this.DataGridTableStyle.SelectionBackBrush;

            if ((this.isSelected && (this.editingRow == rowNum)) && !this.IsReadOnly())
            {
                g.FillRectangle(brush, bounds);
            }
            else
            {
                g.FillRectangle(backBrush, bounds);
            }
            g.Clip = clip;
            if (inactive == ButtonState.Inactive)
            {
                ControlPaint.DrawMixedCheckBox(g, checkBoxBounds, ButtonState.Checked);
            }
            else
            {
                ControlPaint.DrawCheckBox(g, checkBoxBounds, inactive);
            }
            if ((this.IsReadOnly() && this.isSelected) && (source.Position == rowNum))
            {
                bounds.Inflate(-1, -1);
                Pen pen = new Pen(brush)
                {
                    DashStyle = DashStyle.Dash
                };
                g.DrawRectangle(pen, bounds);
                pen.Dispose();
                bounds.Inflate(1, 1);
            }
        }
Example #6
0
 /// <summary>
 ///  Renders a CheckBox control.
 /// </summary>
 public static void DrawCheckBox(Graphics g, Point glyphLocation, CheckBoxState state)
 {
     if (RenderWithVisualStyles)
     {
         DrawCheckBoxWithVisualStyles(g, glyphLocation, state);
     }
     else
     {
         Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(g, state));
         if (IsMixed(state))
         {
             ControlPaint.DrawMixedCheckBox(g, glyphBounds, ConvertToButtonState(state));
         }
         else
         {
             ControlPaint.DrawCheckBox(g, glyphBounds, ConvertToButtonState(state));
         }
     }
 }
        internal static void DrawCheckBox(Graphics g, Point glyphLocation, CheckBoxState state, IntPtr hWnd)
        {
            Rectangle glyphBounds = new Rectangle(glyphLocation, GetGlyphSize(g, state, hWnd));

            if (RenderWithVisualStyles)
            {
                InitializeRenderer((int)state);

                using var hdc = new DeviceContextHdcScope(g);
                visualStyleRenderer.DrawBackground(hdc, glyphBounds, hWnd);
            }
            else
            {
                if (IsMixed(state))
                {
                    ControlPaint.DrawMixedCheckBox(g, glyphBounds, ConvertToButtonState(state));
                }
                else
                {
                    ControlPaint.DrawCheckBox(g, glyphBounds, ConvertToButtonState(state));
                }
            }
        }
Example #8
0
        public static void DrawCheckBox(Graphics g, Point_ glyphLocation, Rectangle_ textBounds, string checkBoxText, Font font, TextFormatFlags flags, Image image, Rectangle_ imageBounds, bool focused, CheckBoxState state)
        {
            Rectangle_ bounds = new Rectangle_(glyphLocation, GetGlyphSize(g, state));

            if (Application.RenderWithVisualStyles || always_use_visual_styles == true)
            {
                VisualStyleRenderer vsr = GetCheckBoxRenderer(state);

                vsr.DrawBackground(g, bounds);

                if (image != null)
                {
                    vsr.DrawImage(g, imageBounds, image);
                }

                if (focused)
                {
                    ControlPaint.DrawFocusRectangle(g, textBounds);
                }

                if (checkBoxText != String.Empty)
                {
                    if (state == CheckBoxState.CheckedDisabled || state == CheckBoxState.MixedDisabled || state == CheckBoxState.UncheckedDisabled)
                    {
                        TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.GrayText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.ControlText, flags);
                    }
                }
            }
            else
            {
                switch (state)
                {
                case CheckBoxState.CheckedDisabled:
                case CheckBoxState.MixedDisabled:
                case CheckBoxState.MixedPressed:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Inactive | ButtonState.Checked);
                    break;

                case CheckBoxState.CheckedHot:
                case CheckBoxState.CheckedNormal:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Checked);
                    break;

                case CheckBoxState.CheckedPressed:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Pushed | ButtonState.Checked);
                    break;

                case CheckBoxState.MixedHot:
                case CheckBoxState.MixedNormal:
                    ControlPaint.DrawMixedCheckBox(g, bounds, ButtonState.Checked);
                    break;

                case CheckBoxState.UncheckedDisabled:
                case CheckBoxState.UncheckedPressed:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Inactive);
                    break;

                case CheckBoxState.UncheckedHot:
                case CheckBoxState.UncheckedNormal:
                    ControlPaint.DrawCheckBox(g, bounds, ButtonState.Normal);
                    break;
                }

                if (image != null)
                {
                    g.DrawImage(image, imageBounds);
                }

                if (focused)
                {
                    ControlPaint.DrawFocusRectangle(g, textBounds);
                }

                if (checkBoxText != String.Empty)
                {
                    TextRenderer.DrawText(g, checkBoxText, font, textBounds, SystemColors.ControlText, flags);
                }
            }
        }