Example #1
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);
            }
        }
        /// <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 #3
0
        protected override void RenderControl(Graphics g, ButtonState buttonState, CheckState checkState)
        {
            ButtonState bstate = buttonState;

            switch (checkState)
            {
            case CheckState.Checked: bstate = ButtonState.Checked; break;

            case CheckState.Indeterminate: bstate = ButtonState.All; break;
            }
            ControlPaint.DrawCheckBox(g, ClientRectangle, bstate);
        }
Example #4
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 #5
0
        protected internal override void PaintItem(Graphics g, int index, string text, Font font, Brush textBrush,
                                                   Rectangle itemRect, StringFormat format)
        {
            g.DrawString(text, this.Font, textBrush, itemRect.X + itemRect.Height, itemRect.Y, format);

            Rectangle rect = new Rectangle(itemRect.X, itemRect.Y, itemRect.Height, itemRect.Height);

            if (GetItemChecked(index))
            {
                ControlPaint.DrawCheckBox(g, rect, ButtonState.Checked);
            }
            else
            {
                ControlPaint.DrawCheckBox(g, rect, ButtonState.Normal);
            }
        }
Example #6
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 #7
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 #8
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 #10
0
        private void DrawBox(Graphics graphics)
        {
            int checkX = 0;
            int checkY = 0;

            int checkSize;

            if (FlatStyle == FlatStyle.Flat)
            {
                checkSize = flatCheckSize;
            }
            else
            {
                checkSize = normalCheckSize;
            }

            switch (checkAlign)
            {
            case ContentAlignment.BottomCenter:
                checkX = (Width / 2) - (checkSize / 2);
                checkY = Height - checkSize - 1;
                break;

            case ContentAlignment.BottomLeft:
                checkX = 0;
                checkY = Height - checkSize - 1;
                break;

            case ContentAlignment.BottomRight:
                checkX = Width - checkSize - 1;
                checkY = Height - checkSize - 1;
                break;

            case ContentAlignment.MiddleCenter:
                checkX = (Width / 2) - (checkSize / 2);
                checkY = (Height / 2) - (checkSize / 2);
                break;

            case ContentAlignment.MiddleLeft:
                checkX = 0;
                checkY = (Height / 2) - (checkSize / 2);
                break;

            case ContentAlignment.MiddleRight:
                checkX = Width - checkSize - 1;
                checkY = (Height / 2) - (checkSize / 2);
                break;

            case ContentAlignment.TopCenter:
                checkX = (Width / 2) - (checkSize / 2);
                checkY = 0;
                break;

            case ContentAlignment.TopLeft:
                checkX = 0;
                checkY = 0;
                break;

            case ContentAlignment.TopRight:
                checkX = Width - checkSize - 1;
                checkY = 0;
                break;
            }
            ButtonState checkState = CalculateState();

            ControlPaint.DrawCheckBox
                (graphics, checkX, checkY,
                checkSize, checkSize, checkState);
        }
Example #11
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);
                }
            }
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            object obj2;

            if (this.Font.Height < 0)
            {
                this.Font = Control.DefaultFont;
            }
            if (e.Index < 0)
            {
                return;
            }
            if (e.Index < this.Items.Count)
            {
                obj2 = this.Items[e.Index];
            }
            else
            {
                obj2 = base.NativeGetItemText(e.Index);
            }
            Rectangle   bounds = e.Bounds;
            int         num    = 1;
            int         num2   = this.Font.Height + (2 * num);
            ButtonState normal = ButtonState.Normal;

            if (this.flat)
            {
                normal |= ButtonState.Flat;
            }
            if (e.Index < this.Items.Count)
            {
                switch (this.CheckedItems.GetCheckedState(e.Index))
                {
                case CheckState.Checked:
                    normal |= ButtonState.Checked;
                    break;

                case CheckState.Indeterminate:
                    normal |= ButtonState.Checked | ButtonState.Inactive;
                    break;
                }
            }
            if (Application.RenderWithVisualStyles)
            {
                CheckBoxState state = CheckBoxRenderer.ConvertFromButtonState(normal, false, (e.State & DrawItemState.HotLight) == DrawItemState.HotLight);
                this.idealCheckSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state).Width;
            }
            int num3 = Math.Max((num2 - this.idealCheckSize) / 2, 0);

            if ((num3 + this.idealCheckSize) > bounds.Height)
            {
                num3 = bounds.Height - this.idealCheckSize;
            }
            Rectangle rectangle = new Rectangle(bounds.X + num, bounds.Y + num3, this.idealCheckSize, this.idealCheckSize);

            if (this.RightToLeft == RightToLeft.Yes)
            {
                rectangle.X = ((bounds.X + bounds.Width) - this.idealCheckSize) - num;
            }
            if (Application.RenderWithVisualStyles)
            {
                CheckBoxState state3 = CheckBoxRenderer.ConvertFromButtonState(normal, false, (e.State & DrawItemState.HotLight) == DrawItemState.HotLight);
                CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(rectangle.X, rectangle.Y), state3);
            }
            else
            {
                ControlPaint.DrawCheckBox(e.Graphics, rectangle, normal);
            }
            Rectangle rect = new Rectangle((bounds.X + this.idealCheckSize) + (num * 2), bounds.Y, bounds.Width - (this.idealCheckSize + (num * 2)), bounds.Height);

            if (this.RightToLeft == RightToLeft.Yes)
            {
                rect.X = bounds.X;
            }
            string s         = "";
            Color  highlight = (this.SelectionMode != System.Windows.Forms.SelectionMode.None) ? e.BackColor : this.BackColor;
            Color  grayText  = (this.SelectionMode != System.Windows.Forms.SelectionMode.None) ? e.ForeColor : this.ForeColor;

            if (!base.Enabled)
            {
                grayText = SystemColors.GrayText;
            }
            Font font = this.Font;

            s = base.GetItemText(obj2);
            if ((this.SelectionMode != System.Windows.Forms.SelectionMode.None) && ((e.State & DrawItemState.Selected) == DrawItemState.Selected))
            {
                if (base.Enabled)
                {
                    highlight = SystemColors.Highlight;
                    grayText  = SystemColors.HighlightText;
                }
                else
                {
                    highlight = SystemColors.InactiveBorder;
                    grayText  = SystemColors.GrayText;
                }
            }
            using (Brush brush = new SolidBrush(highlight))
            {
                e.Graphics.FillRectangle(brush, rect);
            }
            Rectangle layoutRectangle = new Rectangle(rect.X + 1, rect.Y, rect.Width - 1, rect.Height - (num * 2));

            if (this.UseCompatibleTextRendering)
            {
                using (StringFormat format = new StringFormat())
                {
                    if (base.UseTabStops)
                    {
                        float   num4     = 3.6f * this.Font.Height;
                        float[] tabStops = new float[15];
                        float   num5     = -(this.idealCheckSize + (num * 2));
                        for (int i = 1; i < tabStops.Length; i++)
                        {
                            tabStops[i] = num4;
                        }
                        if (Math.Abs(num5) < num4)
                        {
                            tabStops[0] = num4 + num5;
                        }
                        else
                        {
                            tabStops[0] = num4;
                        }
                        format.SetTabStops(0f, tabStops);
                    }
                    else if (base.UseCustomTabOffsets)
                    {
                        float[] destination = new float[base.CustomTabOffsets.Count];
                        base.CustomTabOffsets.CopyTo(destination, 0);
                        format.SetTabStops(0f, destination);
                    }
                    if (this.RightToLeft == RightToLeft.Yes)
                    {
                        format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }
                    format.FormatFlags |= StringFormatFlags.NoWrap;
                    format.Trimming     = StringTrimming.None;
                    using (SolidBrush brush2 = new SolidBrush(grayText))
                    {
                        e.Graphics.DrawString(s, font, brush2, layoutRectangle, format);
                    }
                    goto Label_049B;
                }
            }
            TextFormatFlags flags = TextFormatFlags.Default;

            flags |= TextFormatFlags.NoPrefix;
            if (base.UseTabStops || base.UseCustomTabOffsets)
            {
                flags |= TextFormatFlags.ExpandTabs;
            }
            if (this.RightToLeft == RightToLeft.Yes)
            {
                flags |= TextFormatFlags.RightToLeft;
                flags |= TextFormatFlags.Right;
            }
            TextRenderer.DrawText(e.Graphics, s, font, layoutRectangle, grayText, flags);
Label_049B:
            if (((e.State & DrawItemState.Focus) == DrawItemState.Focus) && ((e.State & DrawItemState.NoFocusRect) != DrawItemState.NoFocusRect))
            {
                ControlPaint.DrawFocusRectangle(e.Graphics, rect, grayText, highlight);
            }
        }