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)
 {
     if (cellStyle == null)
     {
         throw new ArgumentNullException("cellStyle");
     }
     if (DataGridViewCell.PaintBorder(paintParts))
     {
         this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
     }
     if (DataGridViewCell.PaintBackground(paintParts))
     {
         Rectangle rect       = cellBounds;
         Rectangle rectangle2 = this.BorderWidths(advancedBorderStyle);
         rect.Offset(rectangle2.X, rectangle2.Y);
         rect.Width  -= rectangle2.Right;
         rect.Height -= rectangle2.Bottom;
         bool       flag        = (dataGridViewElementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;
         SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
         if (cachedBrush.Color.A == 0xff)
         {
             graphics.FillRectangle(cachedBrush, rect);
         }
     }
 }
Exemplo n.º 2
0
        /// <include file='doc\DataGridViewHeaderCell.uex' path='docs/doc[@for="DataGridViewHeaderCell.Paint"]/*' />
        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)
        {
            if (cellStyle == null)
            {
                throw new ArgumentNullException(nameof(cellStyle));
            }

            if (DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            if (DataGridViewCell.PaintBackground(paintParts))
            {
                Rectangle valBounds    = cellBounds;
                Rectangle borderWidths = BorderWidths(advancedBorderStyle);

                valBounds.Offset(borderWidths.X, borderWidths.Y);
                valBounds.Width  -= borderWidths.Right;
                valBounds.Height -= borderWidths.Bottom;

                bool       cellSelected = (dataGridViewElementState & DataGridViewElementStates.Selected) != 0;
                SolidBrush br           = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
                if (br.Color.A == 255)
                {
                    graphics.FillRectangle(br, valBounds);
                }
            }
        }
Exemplo n.º 3
0
        // PaintPrivate is used in three places that need to duplicate the paint code:
        // 1. DataGridViewCell::Paint method
        // 2. DataGridViewCell::GetContentBounds
        // 3. DataGridViewCell::GetErrorIconBounds
        //
        // if computeContentBounds is true then PaintPrivate returns the contentBounds
        // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds
        // else it returns Rectangle.Empty;
        private Rectangle PaintPrivate(Graphics g,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates elementState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            Rectangle resultBounds;
            Rectangle valBounds    = cellBounds;
            Rectangle borderWidths = BorderWidths(advancedBorderStyle);

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            if (valBounds.Width > 0 && valBounds.Height > 0 && (paint || computeContentBounds))
            {
                Rectangle imgBounds = valBounds;
                if (cellStyle.Padding != Padding.Empty)
                {
                    if (DataGridView.RightToLeftInternal)
                    {
                        imgBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        imgBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    imgBounds.Width  -= cellStyle.Padding.Horizontal;
                    imgBounds.Height -= cellStyle.Padding.Vertical;
                }

                bool       cellSelected = (elementState & DataGridViewElementStates.Selected) != 0;
                SolidBrush br           = DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);

                if (imgBounds.Width > 0 && imgBounds.Height > 0)
                {
                    Image img = formattedValue as Image;
                    Icon  ico = null;
                    if (img == null)
                    {
                        ico = formattedValue as Icon;
                    }
                    if (ico != null || img != null)
                    {
                        DataGridViewImageCellLayout imageLayout = ImageLayout;
                        if (imageLayout == DataGridViewImageCellLayout.NotSet)
                        {
                            if (OwningColumn is DataGridViewImageColumn)
                            {
                                imageLayout = ((DataGridViewImageColumn)OwningColumn).ImageLayout;
                                Debug.Assert(imageLayout != DataGridViewImageCellLayout.NotSet);
                            }
                            else
                            {
                                imageLayout = DataGridViewImageCellLayout.Normal;
                            }
                        }

                        if (imageLayout == DataGridViewImageCellLayout.Stretch)
                        {
                            if (paint)
                            {
                                if (DataGridViewCell.PaintBackground(paintParts))
                                {
                                    DataGridViewCell.PaintPadding(g, valBounds, cellStyle, br, DataGridView.RightToLeftInternal);
                                }
                                if (DataGridViewCell.PaintContentForeground(paintParts))
                                {
                                    if (img != null)
                                    {
                                        //

                                        ImageAttributes attr = new ImageAttributes();

                                        attr.SetWrapMode(WrapMode.TileFlipXY);
                                        g.DrawImage(img, imgBounds, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, attr);
                                        attr.Dispose();
                                    }
                                    else
                                    {
                                        g.DrawIcon(ico, imgBounds);
                                    }
                                }
                            }

                            resultBounds = imgBounds;
                        }
                        else
                        {
                            Rectangle imgBounds2 = ImgBounds(imgBounds, (img == null) ? ico.Width : img.Width, (img == null) ? ico.Height : img.Height, imageLayout, cellStyle);
                            resultBounds = imgBounds2;

                            if (paint)
                            {
                                if (DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
                                {
                                    g.FillRectangle(br, valBounds);
                                }
                                if (DataGridViewCell.PaintContentForeground(paintParts))
                                {
                                    //paint the image
                                    Region reg = g.Clip;
                                    g.SetClip(Rectangle.Intersect(Rectangle.Intersect(imgBounds2, imgBounds), Rectangle.Truncate(g.VisibleClipBounds)));
                                    if (img != null)
                                    {
                                        g.DrawImage(img, imgBounds2);
                                    }
                                    else
                                    {
                                        g.DrawIconUnstretched(ico, imgBounds2);
                                    }
                                    g.Clip = reg;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
                        {
                            g.FillRectangle(br, valBounds);
                        }
                        resultBounds = Rectangle.Empty;
                    }
                }
                else
                {
                    if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
                    {
                        g.FillRectangle(br, valBounds);
                    }
                    resultBounds = Rectangle.Empty;
                }

                Point ptCurrentCell = DataGridView.CurrentCellAddress;
                if (paint &&
                    DataGridViewCell.PaintFocus(paintParts) &&
                    ptCurrentCell.X == ColumnIndex &&
                    ptCurrentCell.Y == rowIndex &&
                    DataGridView.ShowFocusCues &&
                    DataGridView.Focused)
                {
                    // Draw focus rectangle
                    ControlPaint.DrawFocusRectangle(g, valBounds, Color.Empty, br.Color);
                }

                if (DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts))
                {
                    PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, valBounds, errorText);
                }
            }
            else if (computeErrorIconBounds)
            {
                if (!string.IsNullOrEmpty(errorText))
                {
                    resultBounds = ComputeErrorIconBounds(valBounds);
                }
                else
                {
                    resultBounds = Rectangle.Empty;
                }
            }
            else
            {
                Debug.Assert(valBounds.Height <= 0 || valBounds.Width <= 0);
                resultBounds = Rectangle.Empty;
            }

            return(resultBounds);
        }
        private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint)
        {
            Rectangle empty;
            Point     point;

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            Rectangle cellValueBounds = cellBounds;
            Rectangle rectangle3      = this.BorderWidths(advancedBorderStyle);

            cellValueBounds.Offset(rectangle3.X, rectangle3.Y);
            cellValueBounds.Width  -= rectangle3.Right;
            cellValueBounds.Height -= rectangle3.Bottom;
            if (((cellValueBounds.Width <= 0) || (cellValueBounds.Height <= 0)) || (!paint && !computeContentBounds))
            {
                if (computeErrorIconBounds)
                {
                    if (!string.IsNullOrEmpty(errorText))
                    {
                        return(base.ComputeErrorIconBounds(cellValueBounds));
                    }
                    return(Rectangle.Empty);
                }
                return(Rectangle.Empty);
            }
            Rectangle destRect = cellValueBounds;

            if (cellStyle.Padding != Padding.Empty)
            {
                if (base.DataGridView.RightToLeftInternal)
                {
                    destRect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    destRect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                destRect.Width  -= cellStyle.Padding.Horizontal;
                destRect.Height -= cellStyle.Padding.Vertical;
            }
            bool       flag        = (elementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;
            SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);

            if ((destRect.Width > 0) && (destRect.Height > 0))
            {
                Image image = formattedValue as Image;
                Icon  icon  = null;
                if (image == null)
                {
                    icon = formattedValue as Icon;
                }
                if ((icon != null) || (image != null))
                {
                    DataGridViewImageCellLayout imageLayout = this.ImageLayout;
                    switch (imageLayout)
                    {
                    case DataGridViewImageCellLayout.NotSet:
                        if (base.OwningColumn is DataGridViewImageColumn)
                        {
                            imageLayout = ((DataGridViewImageColumn)base.OwningColumn).ImageLayout;
                        }
                        else
                        {
                            imageLayout = DataGridViewImageCellLayout.Normal;
                        }
                        break;

                    case DataGridViewImageCellLayout.Stretch:
                        if (paint)
                        {
                            if (DataGridViewCell.PaintBackground(paintParts))
                            {
                                DataGridViewCell.PaintPadding(g, cellValueBounds, cellStyle, cachedBrush, base.DataGridView.RightToLeftInternal);
                            }
                            if (DataGridViewCell.PaintContentForeground(paintParts))
                            {
                                if (image != null)
                                {
                                    ImageAttributes imageAttr = new ImageAttributes();
                                    imageAttr.SetWrapMode(WrapMode.TileFlipXY);
                                    g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
                                    imageAttr.Dispose();
                                }
                                else
                                {
                                    g.DrawIcon(icon, destRect);
                                }
                            }
                        }
                        empty = destRect;
                        goto Label_037E;
                    }
                    Rectangle a = this.ImgBounds(destRect, (image == null) ? icon.Width : image.Width, (image == null) ? icon.Height : image.Height, imageLayout, cellStyle);
                    empty = a;
                    if (paint)
                    {
                        if (DataGridViewCell.PaintBackground(paintParts) && (cachedBrush.Color.A == 0xff))
                        {
                            g.FillRectangle(cachedBrush, cellValueBounds);
                        }
                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            Region clip = g.Clip;
                            g.SetClip(Rectangle.Intersect(Rectangle.Intersect(a, destRect), Rectangle.Truncate(g.VisibleClipBounds)));
                            if (image != null)
                            {
                                g.DrawImage(image, a);
                            }
                            else
                            {
                                g.DrawIconUnstretched(icon, a);
                            }
                            g.Clip = clip;
                        }
                    }
                }
                else
                {
                    if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
                    {
                        g.FillRectangle(cachedBrush, cellValueBounds);
                    }
                    empty = Rectangle.Empty;
                }
            }
            else
            {
                if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
                {
                    g.FillRectangle(cachedBrush, cellValueBounds);
                }
                empty = Rectangle.Empty;
            }
Label_037E:
            point = base.DataGridView.CurrentCellAddress;
            if (((paint && DataGridViewCell.PaintFocus(paintParts)) && ((point.X == base.ColumnIndex) && (point.Y == rowIndex))) && (base.DataGridView.ShowFocusCues && base.DataGridView.Focused))
            {
                ControlPaint.DrawFocusRectangle(g, cellValueBounds, Color.Empty, cachedBrush.Color);
            }
            if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
            }
            return(empty);
        }
Exemplo n.º 5
0
        // PaintPrivate is used in three places that need to duplicate the paint code:
        // 1. DataGridViewCell::Paint method
        // 2. DataGridViewCell::GetContentBounds
        // 3. DataGridViewCell::GetErrorIconBounds
        //
        // if computeContentBounds is true then PaintPrivate returns the contentBounds
        // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds
        // else it returns Rectangle.Empty;
        private Rectangle PaintPrivate(Graphics g,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates cellState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            Rectangle resultBounds = Rectangle.Empty;

            Rectangle borderWidths = BorderWidths(advancedBorderStyle);
            Rectangle valBounds    = cellBounds;

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            Point      ptCurrentCell = DataGridView.CurrentCellAddress;
            bool       cellCurrent   = ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex;
            bool       cellSelected  = (cellState & DataGridViewElementStates.Selected) != 0;
            SolidBrush br            = DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);

            if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255)
            {
                g.FillRectangle(br, valBounds);
            }

            if (cellStyle.Padding != Padding.Empty)
            {
                if (DataGridView.RightToLeftInternal)
                {
                    valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                valBounds.Width  -= cellStyle.Padding.Horizontal;
                valBounds.Height -= cellStyle.Padding.Vertical;
            }

            Rectangle errorBounds = valBounds;

            if (formattedValue is string formattedValueStr && (paint || computeContentBounds))
            {
                // Font independent margins
                valBounds.Offset(DATAGRIDVIEWLINKCELL_horizontalTextMarginLeft, DATAGRIDVIEWLINKCELL_verticalTextMarginTop);
                valBounds.Width  -= DATAGRIDVIEWLINKCELL_horizontalTextMarginLeft + DATAGRIDVIEWLINKCELL_horizontalTextMarginRight;
                valBounds.Height -= DATAGRIDVIEWLINKCELL_verticalTextMarginTop + DATAGRIDVIEWLINKCELL_verticalTextMarginBottom;
                if ((cellStyle.Alignment & anyBottom) != 0)
                {
                    valBounds.Height -= DATAGRIDVIEWLINKCELL_verticalTextMarginBottom;
                }

                Font linkFont  = null;
                Font hoverFont = null;
                LinkUtilities.EnsureLinkFonts(cellStyle.Font, LinkBehavior, ref linkFont, ref hoverFont);
                TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                // paint the focus rectangle around the link
                if (paint)
                {
                    if (valBounds.Width > 0 && valBounds.Height > 0)
                    {
                        if (cellCurrent &&
                            DataGridView.ShowFocusCues &&
                            DataGridView.Focused &&
                            DataGridViewCell.PaintFocus(paintParts))
                        {
                            Rectangle focusBounds = DataGridViewUtilities.GetTextBounds(valBounds,
                                                                                        formattedValueStr,
                                                                                        flags,
                                                                                        cellStyle,
                                                                                        LinkState == LinkState.Hover ? hoverFont : linkFont);
                            if ((cellStyle.Alignment & anyLeft) != 0)
                            {
                                focusBounds.X--;
                                focusBounds.Width++;
                            }
                            else if ((cellStyle.Alignment & anyRight) != 0)
                            {
                                focusBounds.X++;
                                focusBounds.Width++;
                            }
                            focusBounds.Height += 2;
                            ControlPaint.DrawFocusRectangle(g, focusBounds, Color.Empty, br.Color);
                        }
                        Color linkColor;
                        if ((LinkState & LinkState.Active) == LinkState.Active)
                        {
                            linkColor = ActiveLinkColor;
                        }
                        else if (LinkVisited)
                        {
                            linkColor = VisitedLinkColor;
                        }
                        else
                        {
                            linkColor = LinkColor;
                        }
                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            if ((flags & TextFormatFlags.SingleLine) != 0)
                            {
                                flags |= TextFormatFlags.EndEllipsis;
                            }
                            TextRenderer.DrawText(g,
                                                  formattedValueStr,
                                                  LinkState == LinkState.Hover ? hoverFont : linkFont,
                                                  valBounds,
                                                  linkColor,
                                                  flags);
                        }
                    }
                    else if (cellCurrent &&
                             DataGridView.ShowFocusCues &&
                             DataGridView.Focused &&
                             DataGridViewCell.PaintFocus(paintParts) &&
                             errorBounds.Width > 0 &&
                             errorBounds.Height > 0)
                    {
                        // Draw focus rectangle
                        ControlPaint.DrawFocusRectangle(g, errorBounds, Color.Empty, br.Color);
                    }
                }
                else
                {
                    Debug.Assert(computeContentBounds);
                    resultBounds = DataGridViewUtilities.GetTextBounds(valBounds,
                                                                       formattedValueStr,
                                                                       flags,
                                                                       cellStyle,
                                                                       LinkState == LinkState.Hover ? hoverFont : linkFont);
                }
                linkFont.Dispose();
                hoverFont.Dispose();
            }
        // PaintPrivate is used in three places that need to duplicate the paint code:
        // 1. DataGridViewCell::Paint method
        // 2. DataGridViewCell::GetContentBounds
        // 3. DataGridViewCell::GetErrorIconBounds
        //
        // if computeContentBounds is true then PaintPrivate returns the contentBounds
        // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds
        // else it returns Rectangle.Empty;
        private Rectangle PaintPrivate(Graphics graphics,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates cellState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            // If computeContentBounds == TRUE then resultBounds will be the contentBounds.
            // If computeErrorIconBounds == TRUE then resultBounds will be the error icon bounds.
            // Else resultBounds will be Rectangle.Empty;
            Rectangle resultBounds = Rectangle.Empty;

            Rectangle valBounds    = cellBounds;
            Rectangle borderWidths = BorderWidths(advancedBorderStyle);

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            bool cellSelected = (cellState & DataGridViewElementStates.Selected) != 0;

            if (paint && DataGridViewCell.PaintBackground(paintParts))
            {
                if (this.DataGridView.ApplyVisualStylesToHeaderCells)
                {
                    // XP Theming
                    int state = (int)HeaderItemState.Normal;

                    if (this.ButtonState != ButtonState.Normal)
                    {
                        Debug.Assert(this.ButtonState == ButtonState.Pushed);
                        state = (int)HeaderItemState.Pressed;
                    }
                    else if (this.DataGridView.MouseEnteredCellAddress.Y == rowIndex && this.DataGridView.MouseEnteredCellAddress.X == this.ColumnIndex)
                    {
                        state = (int)HeaderItemState.Hot;
                    }

                    valBounds.Inflate(16, 16);
                    DataGridViewTopLeftHeaderCellRenderer.DrawHeader(graphics, valBounds, state);
                    valBounds.Inflate(-16, -16);
                }
                else
                {
                    SolidBrush br = this.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
                    if (br.Color.A == 255)
                    {
                        graphics.FillRectangle(br, valBounds);
                    }
                }
            }

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            if (cellStyle.Padding != Padding.Empty)
            {
                if (this.DataGridView.RightToLeftInternal)
                {
                    valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                valBounds.Width  -= cellStyle.Padding.Horizontal;
                valBounds.Height -= cellStyle.Padding.Vertical;
            }

            Rectangle errorBounds       = valBounds;
            string    formattedValueStr = formattedValue as string;

            // Font independent margins
            valBounds.Offset(DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginLeft, DATAGRIDVIEWTOPLEFTHEADERCELL_verticalTextMargin);
            valBounds.Width  -= DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginLeft + DATAGRIDVIEWTOPLEFTHEADERCELL_horizontalTextMarginRight;
            valBounds.Height -= 2 * DATAGRIDVIEWTOPLEFTHEADERCELL_verticalTextMargin;
            if (valBounds.Width > 0 &&
                valBounds.Height > 0 &&
                !String.IsNullOrEmpty(formattedValueStr) &&
                (paint || computeContentBounds))
            {
                Color textColor;
                if (this.DataGridView.ApplyVisualStylesToHeaderCells)
                {
                    textColor = DataGridViewTopLeftHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                }
                else
                {
                    textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                }
                TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                if (paint)
                {
                    if (DataGridViewCell.PaintContentForeground(paintParts))
                    {
                        if ((flags & TextFormatFlags.SingleLine) != 0)
                        {
                            flags |= TextFormatFlags.EndEllipsis;
                        }
                        TextRenderer.DrawText(graphics,
                                              formattedValueStr,
                                              cellStyle.Font,
                                              valBounds,
                                              textColor,
                                              flags);
                    }
                }
                else
                {
                    Debug.Assert(computeContentBounds);
                    resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedValueStr, flags, cellStyle);
                }
            }
            else if (computeErrorIconBounds && !String.IsNullOrEmpty(errorText))
            {
                resultBounds = ComputeErrorIconBounds(errorBounds);
            }

            if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText);
            }

            return(resultBounds);
        }
Exemplo n.º 7
0
        private Rectangle PaintPrivate(Graphics graphics,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates dataGridViewElementState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            // If computeContentBounds == TRUE then resultBounds will be the contentBounds.
            // If computeErrorIconBounds == TRUE then resultBounds will be the error icon bounds.
            // Else resultBounds will be Rectangle.Empty;
            Rectangle resultBounds = Rectangle.Empty;

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            Rectangle valBounds    = cellBounds;
            Rectangle borderWidths = BorderWidths(advancedBorderStyle);

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;
            Rectangle backgroundBounds = valBounds;

            bool cellSelected = (dataGridViewElementState & DataGridViewElementStates.Selected) != 0;

            if (DataGridView.ApplyVisualStylesToHeaderCells)
            {
                if (cellStyle.Padding != Padding.Empty)
                {
                    if (DataGridView.RightToLeftInternal)
                    {
                        valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    valBounds.Width  -= cellStyle.Padding.Horizontal;
                    valBounds.Height -= cellStyle.Padding.Vertical;
                }

                if (backgroundBounds.Width > 0 && backgroundBounds.Height > 0)
                {
                    if (paint && DataGridViewCell.PaintBackground(paintParts))
                    {
                        // Theming
                        int state = (int)HeaderItemState.Normal;
                        if (DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect ||
                            DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect)
                        {
                            if (ButtonState != ButtonState.Normal)
                            {
                                Debug.Assert(ButtonState == ButtonState.Pushed);
                                state = (int)HeaderItemState.Pressed;
                            }
                            else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                     DataGridView.MouseEnteredCellAddress.X == -1)
                            {
                                state = (int)HeaderItemState.Hot;
                            }
                            else if (cellSelected)
                            {
                                state = (int)HeaderItemState.Pressed;
                            }
                        }
                        // Flip the column header background
                        using (Bitmap bmFlipXPThemes = new Bitmap(backgroundBounds.Height, backgroundBounds.Width))
                        {
                            using (Graphics gFlip = Graphics.FromImage(bmFlipXPThemes))
                            {
                                DataGridViewRowHeaderCellRenderer.DrawHeader(gFlip, new Rectangle(0, 0, backgroundBounds.Height, backgroundBounds.Width), state);
                                bmFlipXPThemes.RotateFlip(DataGridView.RightToLeftInternal ? RotateFlipType.Rotate90FlipNone : RotateFlipType.Rotate270FlipY);

                                graphics.DrawImage(bmFlipXPThemes,
                                                   backgroundBounds,
                                                   new Rectangle(0, 0, backgroundBounds.Width, backgroundBounds.Height),
                                                   GraphicsUnit.Pixel);
                            }
                        }
                    }
                    // update the val bounds
                    Rectangle rectThemeMargins = GetThemeMargins(graphics);
                    if (DataGridView.RightToLeftInternal)
                    {
                        valBounds.X += rectThemeMargins.Height;
                    }
                    else
                    {
                        valBounds.X += rectThemeMargins.Y;
                    }
                    valBounds.Width  -= rectThemeMargins.Y + rectThemeMargins.Height;
                    valBounds.Height -= rectThemeMargins.X + rectThemeMargins.Width;
                    valBounds.Y      += rectThemeMargins.X;
                }
            }
            else
            {
                // No visual style applied
                if (valBounds.Width > 0 && valBounds.Height > 0)
                {
                    Color brushColor = PaintSelectionBackground(paintParts) && cellSelected
                        ? cellStyle.SelectionBackColor
                        : cellStyle.BackColor;

                    if (paint && PaintBackground(paintParts) && !brushColor.HasTransparency())
                    {
                        using var brush = brushColor.GetCachedSolidBrushScope();
                        graphics.FillRectangle(brush, valBounds);
                    }
                }

                if (cellStyle.Padding != Padding.Empty)
                {
                    if (DataGridView.RightToLeftInternal)
                    {
                        valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    valBounds.Width  -= cellStyle.Padding.Horizontal;
                    valBounds.Height -= cellStyle.Padding.Vertical;
                }
            }

            Bitmap bmp = null;

            if (valBounds.Width > 0 && valBounds.Height > 0)
            {
                Rectangle errorBounds     = valBounds;
                string    formattedString = formattedValue as string;
                if (!string.IsNullOrEmpty(formattedString))
                {
                    // There is text to display
                    if (valBounds.Width >= s_iconsWidth +
                        2 * RowHeaderIconMarginWidth &&
                        valBounds.Height >= s_iconsHeight +
                        2 * RowHeaderIconMarginHeight)
                    {
                        if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                        {
                            // There is enough room for the potential glyph which is the first priority
                            if (DataGridView.CurrentCellAddress.Y == rowIndex)
                            {
                                if (DataGridView.VirtualMode)
                                {
                                    if (DataGridView.IsCurrentRowDirty && DataGridView.ShowEditingIcon)
                                    {
                                        bmp = GetPencilBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else if (DataGridView.NewRowIndex == rowIndex)
                                    {
                                        bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else
                                    {
                                        bmp = GetArrowBitmap(DataGridView.RightToLeftInternal);
                                    }
                                }
                                else
                                {
                                    if (DataGridView.IsCurrentCellDirty && DataGridView.ShowEditingIcon)
                                    {
                                        bmp = GetPencilBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else if (DataGridView.NewRowIndex == rowIndex)
                                    {
                                        bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else
                                    {
                                        bmp = GetArrowBitmap(DataGridView.RightToLeftInternal);
                                    }
                                }
                            }
                            else if (DataGridView.NewRowIndex == rowIndex)
                            {
                                bmp = DataGridViewRowHeaderCell.StarBitmap;
                            }
                            if (bmp != null)
                            {
                                Color iconColor;
                                if (DataGridView.ApplyVisualStylesToHeaderCells)
                                {
                                    iconColor = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                                }
                                else
                                {
                                    iconColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                                }
                                lock (bmp)
                                {
                                    PaintIcon(graphics, bmp, valBounds, iconColor);
                                }
                            }
                        }
                        if (!DataGridView.RightToLeftInternal)
                        {
                            valBounds.X += s_iconsWidth + 2 * RowHeaderIconMarginWidth;
                        }
                        valBounds.Width -= s_iconsWidth + 2 * RowHeaderIconMarginWidth;
                        Debug.Assert(valBounds.Width >= 0);
                        Debug.Assert(valBounds.Height >= 0);
                    }
                    // Second priority is text
                    // Font independent margins
                    valBounds.Offset(HorizontalTextMarginLeft + ContentMarginWidth, VerticalTextMargin);
                    valBounds.Width  -= HorizontalTextMarginLeft + 2 * ContentMarginWidth + HorizontalTextMarginRight;
                    valBounds.Height -= 2 * VerticalTextMargin;
                    if (valBounds.Width > 0 && valBounds.Height > 0)
                    {
                        TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                        if (DataGridView.ShowRowErrors && valBounds.Width > s_iconsWidth + 2 * RowHeaderIconMarginWidth)
                        {
                            // Check if the text fits if we remove the room required for the row error icon
                            Size maxBounds = new Size(valBounds.Width - s_iconsWidth - 2 * RowHeaderIconMarginWidth, valBounds.Height);
                            if (DataGridViewCell.TextFitsInBounds(graphics,
                                                                  formattedString,
                                                                  cellStyle.Font,
                                                                  maxBounds,
                                                                  flags))
                            {
                                // There is enough room for both the text and the row error icon, so use it all.
                                if (DataGridView.RightToLeftInternal)
                                {
                                    valBounds.X += s_iconsWidth + 2 * RowHeaderIconMarginWidth;
                                }
                                valBounds.Width -= s_iconsWidth + 2 * RowHeaderIconMarginWidth;
                            }
                        }

                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            if (paint)
                            {
                                Color textColor;
                                if (DataGridView.ApplyVisualStylesToHeaderCells)
                                {
                                    textColor = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                                }
                                else
                                {
                                    textColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                                }
                                if ((flags & TextFormatFlags.SingleLine) != 0)
                                {
                                    flags |= TextFormatFlags.EndEllipsis;
                                }
                                TextRenderer.DrawText(graphics,
                                                      formattedString,
                                                      cellStyle.Font,
                                                      valBounds,
                                                      textColor,
                                                      flags);
                            }
                            else if (computeContentBounds)
                            {
                                resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedString, flags, cellStyle);
                            }
                        }
                    }
                    // Third priority is the row error icon, which may be painted on top of text
                    if (errorBounds.Width >= 3 * RowHeaderIconMarginWidth +
                        2 * s_iconsWidth)
                    {
                        // There is enough horizontal room for the error icon and the glyph
                        if (paint && DataGridView.ShowRowErrors && DataGridViewCell.PaintErrorIcon(paintParts))
                        {
                            PaintErrorIcon(graphics, clipBounds, errorBounds, errorText);
                        }
                        else if (computeErrorIconBounds)
                        {
                            if (!string.IsNullOrEmpty(errorText))
                            {
                                resultBounds = ComputeErrorIconBounds(errorBounds);
                            }
                        }
                    }
                }
                else
                {
                    // There is no text to display
                    if (valBounds.Width >= s_iconsWidth + 2 * RowHeaderIconMarginWidth &&
                        valBounds.Height >= s_iconsHeight + 2 * RowHeaderIconMarginHeight)
                    {
                        if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                        {
                            // There is enough room for the potential icon
                            if (DataGridView.CurrentCellAddress.Y == rowIndex)
                            {
                                if (DataGridView.VirtualMode)
                                {
                                    if (DataGridView.IsCurrentRowDirty && DataGridView.ShowEditingIcon)
                                    {
                                        bmp = GetPencilBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else if (DataGridView.NewRowIndex == rowIndex)
                                    {
                                        bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else
                                    {
                                        bmp = GetArrowBitmap(DataGridView.RightToLeftInternal);
                                    }
                                }
                                else
                                {
                                    if (DataGridView.IsCurrentCellDirty && DataGridView.ShowEditingIcon)
                                    {
                                        bmp = GetPencilBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else if (DataGridView.NewRowIndex == rowIndex)
                                    {
                                        bmp = GetArrowStarBitmap(DataGridView.RightToLeftInternal);
                                    }
                                    else
                                    {
                                        bmp = GetArrowBitmap(DataGridView.RightToLeftInternal);
                                    }
                                }
                            }
                            else if (DataGridView.NewRowIndex == rowIndex)
                            {
                                bmp = DataGridViewRowHeaderCell.StarBitmap;
                            }
                            if (bmp != null)
                            {
                                lock (bmp)
                                {
                                    Color iconColor;
                                    if (DataGridView.ApplyVisualStylesToHeaderCells)
                                    {
                                        iconColor = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                                    }
                                    else
                                    {
                                        iconColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                                    }
                                    PaintIcon(graphics, bmp, valBounds, iconColor);
                                }
                            }
                        }
                    }

                    if (errorBounds.Width >= 3 * RowHeaderIconMarginWidth +
                        2 * s_iconsWidth)
                    {
                        // There is enough horizontal room for the error icon
                        if (paint && DataGridView.ShowRowErrors && DataGridViewCell.PaintErrorIcon(paintParts))
                        {
                            PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText);
                        }
                        else if (computeErrorIconBounds)
                        {
                            if (!string.IsNullOrEmpty(errorText))
                            {
                                resultBounds = ComputeErrorIconBounds(errorBounds);
                            }
                        }
                    }
                }
            }
            // else no room for content or error icon, resultBounds = Rectangle.Empty

            return(resultBounds);
        }
Exemplo n.º 8
0
        private Rectangle PaintPrivate(Graphics g,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates elementState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            Point ptCurrentCell = DataGridView.CurrentCellAddress;
            bool  cellSelected  = (elementState & DataGridViewElementStates.Selected) != 0;
            bool  cellCurrent   = (ptCurrentCell.X == ColumnIndex && ptCurrentCell.Y == rowIndex);

            Rectangle resultBounds;
            string    formattedString = formattedValue as string;

            SolidBrush backBrush = DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
            SolidBrush foreBrush = DataGridView.GetCachedBrush(cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor);

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            Rectangle valBounds    = cellBounds;
            Rectangle borderWidths = BorderWidths(advancedBorderStyle);

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            if (valBounds.Height > 0 && valBounds.Width > 0)
            {
                if (paint && DataGridViewCell.PaintBackground(paintParts) && backBrush.Color.A == 255)
                {
                    g.FillRectangle(backBrush, valBounds);
                }

                if (cellStyle.Padding != Padding.Empty)
                {
                    if (DataGridView.RightToLeftInternal)
                    {
                        valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    valBounds.Width  -= cellStyle.Padding.Horizontal;
                    valBounds.Height -= cellStyle.Padding.Vertical;
                }

                Rectangle errorBounds = valBounds;

                if (valBounds.Height > 0 && valBounds.Width > 0 && (paint || computeContentBounds))
                {
                    if (FlatStyle == FlatStyle.Standard || FlatStyle == FlatStyle.System)
                    {
                        if (DataGridView.ApplyVisualStylesToInnerCells)
                        {
                            if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                            {
                                PushButtonState pbState = VisualStyles.PushButtonState.Normal;
                                if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                                {
                                    pbState = VisualStyles.PushButtonState.Pressed;
                                }
                                else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                         DataGridView.MouseEnteredCellAddress.X == ColumnIndex &&
                                         mouseInContentBounds)
                                {
                                    pbState = VisualStyles.PushButtonState.Hot;
                                }
                                if (DataGridViewCell.PaintFocus(paintParts) &&
                                    cellCurrent &&
                                    DataGridView.ShowFocusCues &&
                                    DataGridView.Focused)
                                {
                                    pbState |= VisualStyles.PushButtonState.Default;
                                }
                                DataGridViewButtonCellRenderer.DrawButton(g, valBounds, (int)pbState);
                            }
                            resultBounds = valBounds;
                            valBounds    = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, valBounds);
                        }
                        else
                        {
                            if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                            {
                                ControlPaint.DrawBorder(g, valBounds, SystemColors.Control,
                                                        (ButtonState == ButtonState.Normal) ? ButtonBorderStyle.Outset : ButtonBorderStyle.Inset);
                            }
                            resultBounds = valBounds;
                            valBounds.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height);
                        }
                    }
                    else if (FlatStyle == FlatStyle.Flat)
                    {
                        // ButtonBase::PaintFlatDown and ButtonBase::PaintFlatUp paint the border in the same way
                        valBounds.Inflate(-1, -1);
                        if (paint && PaintContentBackground(paintParts))
                        {
                            ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, foreBrush.Color, true /*isDefault == true*/);

                            if (backBrush.Color.A == 255)
                            {
                                if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                                {
                                    ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintFlatRender(
                                        g,
                                        cellStyle.ForeColor,
                                        cellStyle.BackColor,
                                        DataGridView.Enabled).Calculate();

                                    using var hdc    = new DeviceContextHdcScope(g);
                                    using var hbrush = new Gdi32.CreateBrushScope(
                                              colors.options.highContrast ? colors.buttonShadow : colors.lowHighlight);
                                    hdc.FillRectangle(valBounds, hbrush);
                                }
                                else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                         DataGridView.MouseEnteredCellAddress.X == ColumnIndex &&
                                         mouseInContentBounds)
                                {
                                    using var hdc    = new DeviceContextHdcScope(g);
                                    using var hbrush = new Gdi32.CreateBrushScope(SystemColors.ControlDark);
                                    hdc.FillRectangle(valBounds, hbrush);
                                }
                            }
                        }
                        resultBounds = valBounds;
                    }
                    else
                    {
                        Debug.Assert(FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style");
                        valBounds.Inflate(-1, -1);
                        if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                        {
                            if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                            {
                                // paint down
                                ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g,
                                                                                                        cellStyle.ForeColor,
                                                                                                        cellStyle.BackColor,
                                                                                                        DataGridView.Enabled).Calculate();
                                ButtonBaseAdapter.DrawDefaultBorder(g,
                                                                    valBounds,
                                                                    colors.options.highContrast ? colors.windowText : colors.windowFrame,
                                                                    true /*isDefault*/);
                                ControlPaint.DrawBorder(g,
                                                        valBounds,
                                                        colors.options.highContrast ? colors.windowText : colors.buttonShadow,
                                                        ButtonBorderStyle.Solid);
                            }
                            else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                     DataGridView.MouseEnteredCellAddress.X == ColumnIndex &&
                                     mouseInContentBounds)
                            {
                                // paint over
                                ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g,
                                                                                                        cellStyle.ForeColor,
                                                                                                        cellStyle.BackColor,
                                                                                                        DataGridView.Enabled).Calculate();
                                ButtonBaseAdapter.DrawDefaultBorder(g,
                                                                    valBounds,
                                                                    colors.options.highContrast ? colors.windowText : colors.buttonShadow,
                                                                    false /*isDefault*/);
                                ButtonBaseAdapter.Draw3DLiteBorder(g, valBounds, colors, true);
                            }
                            else
                            {
                                // paint up
                                ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g,
                                                                                                        cellStyle.ForeColor,
                                                                                                        cellStyle.BackColor,
                                                                                                        DataGridView.Enabled).Calculate();
                                ButtonBaseAdapter.DrawDefaultBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.buttonShadow, false /*isDefault*/);
                                ButtonBaseAdapter.DrawFlatBorder(g, valBounds, colors.options.highContrast ? colors.windowText : colors.buttonShadow);
                            }
                        }
                        resultBounds = valBounds;
                    }
                }
                else if (computeErrorIconBounds)
                {
                    if (!string.IsNullOrEmpty(errorText))
                    {
                        resultBounds = ComputeErrorIconBounds(errorBounds);
                    }
                    else
                    {
                        resultBounds = Rectangle.Empty;
                    }
                }
                else
                {
                    Debug.Assert(valBounds.Height <= 0 || valBounds.Width <= 0);
                    resultBounds = Rectangle.Empty;
                }

                if (paint &&
                    DataGridViewCell.PaintFocus(paintParts) &&
                    cellCurrent &&
                    DataGridView.ShowFocusCues &&
                    DataGridView.Focused &&
                    valBounds.Width > 2 * SystemInformation.Border3DSize.Width + 1 &&
                    valBounds.Height > 2 * SystemInformation.Border3DSize.Height + 1)
                {
                    // Draw focus rectangle
                    if (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard)
                    {
                        ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(valBounds, -1, -1), Color.Empty, SystemColors.Control);
                    }
                    else if (FlatStyle == FlatStyle.Flat)
                    {
                        if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 ||
                            (DataGridView.CurrentCellAddress.Y == rowIndex && DataGridView.CurrentCellAddress.X == ColumnIndex))
                        {
                            ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintFlatRender(g,
                                                                                                   cellStyle.ForeColor,
                                                                                                   cellStyle.BackColor,
                                                                                                   DataGridView.Enabled).Calculate();
                            string text = formattedString ?? string.Empty;

                            ButtonBaseAdapter.LayoutOptions options = ButtonInternal.ButtonFlatAdapter.PaintFlatLayout(g,
                                                                                                                       true,
                                                                                                                       SystemInformation.HighContrast,
                                                                                                                       1,
                                                                                                                       valBounds,
                                                                                                                       Padding.Empty,
                                                                                                                       false,
                                                                                                                       cellStyle.Font,
                                                                                                                       text,
                                                                                                                       DataGridView.Enabled,
                                                                                                                       DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment),
                                                                                                                       DataGridView.RightToLeft);
                            options.everettButtonCompat = false;
                            ButtonBaseAdapter.LayoutData layout = options.Layout();

                            ButtonInternal.ButtonBaseAdapter.DrawFlatFocus(g,
                                                                           layout.focus,
                                                                           colors.options.highContrast ? colors.windowText : colors.constrastButtonShadow);
                        }
                    }
                    else
                    {
                        Debug.Assert(FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style");
                        if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 ||
                            (DataGridView.CurrentCellAddress.Y == rowIndex && DataGridView.CurrentCellAddress.X == ColumnIndex))
                        {
                            // If we are painting the current cell, then paint the text up.
                            // If we are painting the current cell and the current cell is pressed down, then paint the text down.
                            bool   paintUp = (ButtonState == ButtonState.Normal);
                            string text    = formattedString ?? string.Empty;
                            ButtonBaseAdapter.LayoutOptions options = ButtonInternal.ButtonPopupAdapter.PaintPopupLayout(g,
                                                                                                                         paintUp,
                                                                                                                         SystemInformation.HighContrast ? 2 : 1,
                                                                                                                         valBounds,
                                                                                                                         Padding.Empty,
                                                                                                                         false,
                                                                                                                         cellStyle.Font,
                                                                                                                         text,
                                                                                                                         DataGridView.Enabled,
                                                                                                                         DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment),
                                                                                                                         DataGridView.RightToLeft);
                            options.everettButtonCompat = false;
                            ButtonBaseAdapter.LayoutData layout = options.Layout();

                            ControlPaint.DrawFocusRectangle(g,
                                                            layout.focus,
                                                            cellStyle.ForeColor,
                                                            cellStyle.BackColor);
                        }
                    }
                }

                if (formattedString != null && paint && DataGridViewCell.PaintContentForeground(paintParts))
                {
                    // Font independent margins
                    valBounds.Offset(DATAGRIDVIEWBUTTONCELL_horizontalTextMargin, DATAGRIDVIEWBUTTONCELL_verticalTextMargin);
                    valBounds.Width  -= 2 * DATAGRIDVIEWBUTTONCELL_horizontalTextMargin;
                    valBounds.Height -= 2 * DATAGRIDVIEWBUTTONCELL_verticalTextMargin;

                    if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0 &&
                        FlatStyle != FlatStyle.Flat && FlatStyle != FlatStyle.Popup)
                    {
                        valBounds.Offset(1, 1);
                        valBounds.Width--;
                        valBounds.Height--;
                    }

                    if (valBounds.Width > 0 && valBounds.Height > 0)
                    {
                        Color textColor;
                        if (DataGridView.ApplyVisualStylesToInnerCells &&
                            (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard))
                        {
                            textColor = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetColor(ColorProperty.TextColor);
                        }
                        else
                        {
                            textColor = foreBrush.Color;
                        }
                        TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                        TextRenderer.DrawText(g,
                                              formattedString,
                                              cellStyle.Font,
                                              valBounds,
                                              textColor,
                                              flags);
                    }
                }

                if (DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts))
                {
                    PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, errorBounds, errorText);
                }
            }
            else
            {
                resultBounds = Rectangle.Empty;
            }

            return(resultBounds);
        }
Exemplo n.º 9
0
        private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint)
        {
            SolidBrush cachedBrush;
            Rectangle  empty = Rectangle.Empty;

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            Rectangle rectangle2 = this.BorderWidths(advancedBorderStyle);
            Rectangle rect       = cellBounds;

            rect.Offset(rectangle2.X, rectangle2.Y);
            rect.Width  -= rectangle2.Right;
            rect.Height -= rectangle2.Bottom;
            Point currentCellAddress = base.DataGridView.CurrentCellAddress;
            bool  flag  = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex);
            bool  flag2 = flag && (base.DataGridView.EditingControl != null);
            bool  flag3 = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;

            if ((DataGridViewCell.PaintSelectionBackground(paintParts) && flag3) && !flag2)
            {
                cachedBrush = base.DataGridView.GetCachedBrush(cellStyle.SelectionBackColor);
            }
            else
            {
                cachedBrush = base.DataGridView.GetCachedBrush(cellStyle.BackColor);
            }
            if (((paint && DataGridViewCell.PaintBackground(paintParts)) && ((cachedBrush.Color.A == 0xff) && (rect.Width > 0))) && (rect.Height > 0))
            {
                graphics.FillRectangle(cachedBrush, rect);
            }
            if (cellStyle.Padding != Padding.Empty)
            {
                if (base.DataGridView.RightToLeftInternal)
                {
                    rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                rect.Width  -= cellStyle.Padding.Horizontal;
                rect.Height -= cellStyle.Padding.Vertical;
            }
            if (((paint && flag) && (!flag2 && DataGridViewCell.PaintFocus(paintParts))) && ((base.DataGridView.ShowFocusCues && base.DataGridView.Focused) && ((rect.Width > 0) && (rect.Height > 0))))
            {
                ControlPaint.DrawFocusRectangle(graphics, rect, Color.Empty, cachedBrush.Color);
            }
            Rectangle cellValueBounds = rect;
            string    text            = formattedValue as string;

            if ((text != null) && ((paint && !flag2) || computeContentBounds))
            {
                int y = (cellStyle.WrapMode == DataGridViewTriState.True) ? 1 : 2;
                rect.Offset(0, y);
                rect.Width   = rect.Width;
                rect.Height -= y + 1;
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                    if (paint)
                    {
                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default)
                            {
                                flags |= TextFormatFlags.EndEllipsis;
                            }
                            TextRenderer.DrawText(graphics, text, cellStyle.Font, rect, flag3 ? cellStyle.SelectionForeColor : cellStyle.ForeColor, flags);
                        }
                    }
                    else
                    {
                        empty = DataGridViewUtilities.GetTextBounds(rect, text, flags, cellStyle);
                    }
                }
            }
            else if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText))
            {
                empty = base.ComputeErrorIconBounds(cellValueBounds);
            }
            if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                base.PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
            }
            return(empty);
        }
Exemplo n.º 10
0
        // PaintPrivate is used in three places that need to duplicate the paint code:
        // 1. DataGridViewCell::Paint method
        // 2. DataGridViewCell::GetContentBounds
        // 3. DataGridViewCell::GetErrorIconBounds
        //
        // if computeContentBounds is true then PaintPrivate returns the contentBounds
        // else if computeErrorIconBounds is true then PaintPrivate returns the errorIconBounds
        // else it returns Rectangle.Empty;
        private Rectangle PaintPrivate(Graphics graphics,
                                       Rectangle clipBounds,
                                       Rectangle cellBounds,
                                       int rowIndex,
                                       DataGridViewElementStates cellState,
                                       object formattedValue,
                                       string errorText,
                                       DataGridViewCellStyle cellStyle,
                                       DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                       DataGridViewPaintParts paintParts,
                                       bool computeContentBounds,
                                       bool computeErrorIconBounds,
                                       bool paint)
        {
            // Parameter checking.
            // One bit and one bit only should be turned on
            Debug.Assert(paint || computeContentBounds || computeErrorIconBounds);
            Debug.Assert(!paint || !computeContentBounds || !computeErrorIconBounds);
            Debug.Assert(!computeContentBounds || !computeErrorIconBounds || !paint);
            Debug.Assert(!computeErrorIconBounds || !paint || !computeContentBounds);
            Debug.Assert(cellStyle != null);

            // If computeContentBounds == TRUE then resultBounds will be the contentBounds.
            // If computeErrorIconBounds == TRUE then resultBounds will be the error icon bounds.
            // Else resultBounds will be Rectangle.Empty;
            Rectangle resultBounds = Rectangle.Empty;

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }

            Rectangle borderWidths = BorderWidths(advancedBorderStyle);
            Rectangle valBounds    = cellBounds;

            valBounds.Offset(borderWidths.X, borderWidths.Y);
            valBounds.Width  -= borderWidths.Right;
            valBounds.Height -= borderWidths.Bottom;

            SolidBrush br;

            Point ptCurrentCell = this.DataGridView.CurrentCellAddress;
            bool  cellCurrent   = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex;
            bool  cellEdited    = cellCurrent && this.DataGridView.EditingControl != null;
            bool  cellSelected  = (cellState & DataGridViewElementStates.Selected) != 0;

            if (DataGridViewCell.PaintSelectionBackground(paintParts) && cellSelected && !cellEdited)
            {
                br = this.DataGridView.GetCachedBrush(cellStyle.SelectionBackColor);
            }
            else
            {
                br = this.DataGridView.GetCachedBrush(cellStyle.BackColor);
            }

            if (paint && DataGridViewCell.PaintBackground(paintParts) && br.Color.A == 255 && valBounds.Width > 0 && valBounds.Height > 0)
            {
                graphics.FillRectangle(br, valBounds);
            }

            if (cellStyle.Padding != Padding.Empty)
            {
                if (this.DataGridView.RightToLeftInternal)
                {
                    valBounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    valBounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                valBounds.Width  -= cellStyle.Padding.Horizontal;
                valBounds.Height -= cellStyle.Padding.Vertical;
            }

            if (paint && cellCurrent && !cellEdited)
            {
                // Draw focus rectangle
                if (DataGridViewCell.PaintFocus(paintParts) &&
                    this.DataGridView.ShowFocusCues &&
                    this.DataGridView.Focused &&
                    valBounds.Width > 0 &&
                    valBounds.Height > 0)
                {
                    ControlPaint.DrawFocusRectangle(graphics, valBounds, Color.Empty, br.Color);
                }
            }

            Rectangle errorBounds     = valBounds;
            string    formattedString = formattedValue as string;

            if (formattedString != null && ((paint && !cellEdited) || computeContentBounds))
            {
                // Font independent margins
                int verticalTextMarginTop = cellStyle.WrapMode == DataGridViewTriState.True ? DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithWrapping : DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithoutWrapping;
                valBounds.Offset(DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft, verticalTextMarginTop);
                valBounds.Width  -= DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft + DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginRight;
                valBounds.Height -= verticalTextMarginTop + DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginBottom;
                if (valBounds.Width > 0 && valBounds.Height > 0)
                {
                    TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                    if (paint)
                    {
                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            if ((flags & TextFormatFlags.SingleLine) != 0)
                            {
                                flags |= TextFormatFlags.EndEllipsis;
                            }
                            TextRenderer.DrawText(graphics,
                                                  formattedString,
                                                  cellStyle.Font,
                                                  valBounds,
                                                  cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor,
                                                  flags);
                        }
                    }
                    else
                    {
                        resultBounds = DataGridViewUtilities.GetTextBounds(valBounds, formattedString, flags, cellStyle);
                    }
                }
            }
            else if (computeErrorIconBounds)
            {
                if (!string.IsNullOrEmpty(errorText))
                {
                    resultBounds = ComputeErrorIconBounds(errorBounds);
                }
            }
            else
            {
                Debug.Assert(cellEdited || formattedString == null);
                Debug.Assert(paint || computeContentBounds);
            }

            if (this.DataGridView.ShowCellErrors && paint && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, errorBounds, errorText);
            }

            return(resultBounds);
        }
Exemplo n.º 11
0
        private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint)
        {
            Rectangle empty = Rectangle.Empty;

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            Rectangle rect       = cellBounds;
            Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle);

            rect.Offset(rectangle3.X, rectangle3.Y);
            rect.Width  -= rectangle3.Right;
            rect.Height -= rectangle3.Bottom;
            Rectangle destRect = rect;
            bool      flag     = (dataGridViewElementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;

            if (base.DataGridView.ApplyVisualStylesToHeaderCells)
            {
                if (cellStyle.Padding != Padding.Empty)
                {
                    if (base.DataGridView.RightToLeftInternal)
                    {
                        rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    rect.Width  -= cellStyle.Padding.Horizontal;
                    rect.Height -= cellStyle.Padding.Vertical;
                }
                if ((destRect.Width > 0) && (destRect.Height > 0))
                {
                    if (paint && DataGridViewCell.PaintBackground(paintParts))
                    {
                        int headerState = 1;
                        if ((base.DataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect) || (base.DataGridView.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect))
                        {
                            if (base.ButtonState != ButtonState.Normal)
                            {
                                headerState = 3;
                            }
                            else if ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == -1))
                            {
                                headerState = 2;
                            }
                            else if (flag)
                            {
                                headerState = 3;
                            }
                        }
                        using (Bitmap bitmap = new Bitmap(destRect.Height, destRect.Width))
                        {
                            using (Graphics graphics2 = Graphics.FromImage(bitmap))
                            {
                                DataGridViewRowHeaderCellRenderer.DrawHeader(graphics2, new Rectangle(0, 0, destRect.Height, destRect.Width), headerState);
                                bitmap.RotateFlip(base.DataGridView.RightToLeftInternal ? RotateFlipType.Rotate90FlipNone : RotateFlipType.Rotate90FlipX);
                                graphics.DrawImage(bitmap, destRect, new Rectangle(0, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel);
                            }
                        }
                    }
                    Rectangle themeMargins = DataGridViewHeaderCell.GetThemeMargins(graphics);
                    if (base.DataGridView.RightToLeftInternal)
                    {
                        rect.X += themeMargins.Height;
                    }
                    else
                    {
                        rect.X += themeMargins.Y;
                    }
                    rect.Width  -= themeMargins.Y + themeMargins.Height;
                    rect.Height -= themeMargins.X + themeMargins.Width;
                    rect.Y      += themeMargins.X;
                }
            }
            else
            {
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
                    if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
                    {
                        graphics.FillRectangle(cachedBrush, rect);
                    }
                }
                if (cellStyle.Padding != Padding.Empty)
                {
                    if (base.DataGridView.RightToLeftInternal)
                    {
                        rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    rect.Width  -= cellStyle.Padding.Horizontal;
                    rect.Height -= cellStyle.Padding.Vertical;
                }
            }
            Bitmap bmp = null;

            if ((rect.Width > 0) && (rect.Height > 0))
            {
                Rectangle cellValueBounds = rect;
                string    str             = formattedValue as string;
                if (!string.IsNullOrEmpty(str))
                {
                    if ((rect.Width >= 0x12) && (rect.Height >= 15))
                    {
                        if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                        {
                            if (base.DataGridView.CurrentCellAddress.Y == rowIndex)
                            {
                                if (base.DataGridView.VirtualMode)
                                {
                                    if (base.DataGridView.IsCurrentRowDirty && base.DataGridView.ShowEditingIcon)
                                    {
                                        bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal);
                                    }
                                    else if (base.DataGridView.NewRowIndex == rowIndex)
                                    {
                                        bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal);
                                    }
                                    else
                                    {
                                        bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal);
                                    }
                                }
                                else if (base.DataGridView.IsCurrentCellDirty && base.DataGridView.ShowEditingIcon)
                                {
                                    bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal);
                                }
                                else if (base.DataGridView.NewRowIndex == rowIndex)
                                {
                                    bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal);
                                }
                                else
                                {
                                    bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal);
                                }
                            }
                            else if (base.DataGridView.NewRowIndex == rowIndex)
                            {
                                bmp = StarBitmap;
                            }
                            if (bmp != null)
                            {
                                Color color;
                                if (base.DataGridView.ApplyVisualStylesToHeaderCells)
                                {
                                    color = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                                }
                                else
                                {
                                    color = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                                }
                                lock (bmp)
                                {
                                    this.PaintIcon(graphics, bmp, rect, color);
                                }
                            }
                        }
                        if (!base.DataGridView.RightToLeftInternal)
                        {
                            rect.X += 0x12;
                        }
                        rect.Width -= 0x12;
                    }
                    rect.Offset(4, 1);
                    rect.Width  -= 9;
                    rect.Height -= 2;
                    if ((rect.Width > 0) && (rect.Height > 0))
                    {
                        TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                        if (base.DataGridView.ShowRowErrors && (rect.Width > 0x12))
                        {
                            Size maxBounds = new Size((rect.Width - 12) - 6, rect.Height);
                            if (DataGridViewCell.TextFitsInBounds(graphics, str, cellStyle.Font, maxBounds, flags))
                            {
                                if (base.DataGridView.RightToLeftInternal)
                                {
                                    rect.X += 0x12;
                                }
                                rect.Width -= 0x12;
                            }
                        }
                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            if (paint)
                            {
                                Color color2;
                                if (base.DataGridView.ApplyVisualStylesToHeaderCells)
                                {
                                    color2 = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                                }
                                else
                                {
                                    color2 = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                                }
                                if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default)
                                {
                                    flags |= TextFormatFlags.EndEllipsis;
                                }
                                TextRenderer.DrawText(graphics, str, cellStyle.Font, rect, color2, flags);
                            }
                            else if (computeContentBounds)
                            {
                                empty = DataGridViewUtilities.GetTextBounds(rect, str, flags, cellStyle);
                            }
                        }
                    }
                    if (cellValueBounds.Width >= 0x21)
                    {
                        if ((paint && base.DataGridView.ShowRowErrors) && DataGridViewCell.PaintErrorIcon(paintParts))
                        {
                            this.PaintErrorIcon(graphics, clipBounds, cellValueBounds, errorText);
                            return(empty);
                        }
                        if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText))
                        {
                            empty = base.ComputeErrorIconBounds(cellValueBounds);
                        }
                    }
                    return(empty);
                }
                if (((rect.Width >= 0x12) && (rect.Height >= 15)) && (paint && DataGridViewCell.PaintContentBackground(paintParts)))
                {
                    if (base.DataGridView.CurrentCellAddress.Y == rowIndex)
                    {
                        if (base.DataGridView.VirtualMode)
                        {
                            if (base.DataGridView.IsCurrentRowDirty && base.DataGridView.ShowEditingIcon)
                            {
                                bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal);
                            }
                            else if (base.DataGridView.NewRowIndex == rowIndex)
                            {
                                bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal);
                            }
                            else
                            {
                                bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal);
                            }
                        }
                        else if (base.DataGridView.IsCurrentCellDirty && base.DataGridView.ShowEditingIcon)
                        {
                            bmp = GetPencilBitmap(base.DataGridView.RightToLeftInternal);
                        }
                        else if (base.DataGridView.NewRowIndex == rowIndex)
                        {
                            bmp = GetArrowStarBitmap(base.DataGridView.RightToLeftInternal);
                        }
                        else
                        {
                            bmp = GetArrowBitmap(base.DataGridView.RightToLeftInternal);
                        }
                    }
                    else if (base.DataGridView.NewRowIndex == rowIndex)
                    {
                        bmp = StarBitmap;
                    }
                    if (bmp != null)
                    {
                        lock (bmp)
                        {
                            Color color3;
                            if (base.DataGridView.ApplyVisualStylesToHeaderCells)
                            {
                                color3 = DataGridViewRowHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                            }
                            else
                            {
                                color3 = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                            }
                            this.PaintIcon(graphics, bmp, rect, color3);
                        }
                    }
                }
                if (cellValueBounds.Width >= 0x21)
                {
                    if ((paint && base.DataGridView.ShowRowErrors) && DataGridViewCell.PaintErrorIcon(paintParts))
                    {
                        base.PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
                        return(empty);
                    }
                    if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText))
                    {
                        empty = base.ComputeErrorIconBounds(cellValueBounds);
                    }
                }
            }
            return(empty);
        }
        private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object formattedValue, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool paint)
        {
            Rectangle empty = Rectangle.Empty;

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            Rectangle bounds     = cellBounds;
            Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle);

            bounds.Offset(rectangle3.X, rectangle3.Y);
            bounds.Width  -= rectangle3.Right;
            bounds.Height -= rectangle3.Bottom;
            Rectangle destRect = bounds;
            bool      flag     = (dataGridViewElementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;

            if (base.DataGridView.ApplyVisualStylesToHeaderCells)
            {
                if ((cellStyle.Padding != Padding.Empty) && (cellStyle.Padding != Padding.Empty))
                {
                    if (base.DataGridView.RightToLeftInternal)
                    {
                        bounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        bounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    bounds.Width  -= cellStyle.Padding.Horizontal;
                    bounds.Height -= cellStyle.Padding.Vertical;
                }
                if ((paint && DataGridViewCell.PaintBackground(paintParts)) && ((destRect.Width > 0) && (destRect.Height > 0)))
                {
                    int headerState = 1;
                    if (((base.OwningColumn != null) && (base.OwningColumn.SortMode != DataGridViewColumnSortMode.NotSortable)) || ((base.DataGridView.SelectionMode == DataGridViewSelectionMode.FullColumnSelect) || (base.DataGridView.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect)))
                    {
                        if (base.ButtonState != ButtonState.Normal)
                        {
                            headerState = 3;
                        }
                        else if ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex))
                        {
                            headerState = 2;
                        }
                        else if (flag)
                        {
                            headerState = 3;
                        }
                    }
                    if (base.DataGridView.RightToLeftInternal)
                    {
                        Bitmap flipXPThemesBitmap = base.FlipXPThemesBitmap;
                        if (((flipXPThemesBitmap == null) || (flipXPThemesBitmap.Width < destRect.Width)) || (((flipXPThemesBitmap.Width > (2 * destRect.Width)) || (flipXPThemesBitmap.Height < destRect.Height)) || (flipXPThemesBitmap.Height > (2 * destRect.Height))))
                        {
                            flipXPThemesBitmap = base.FlipXPThemesBitmap = new Bitmap(destRect.Width, destRect.Height);
                        }
                        DataGridViewColumnHeaderCellRenderer.DrawHeader(Graphics.FromImage(flipXPThemesBitmap), new Rectangle(0, 0, destRect.Width, destRect.Height), headerState);
                        flipXPThemesBitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        g.DrawImage(flipXPThemesBitmap, destRect, new Rectangle(flipXPThemesBitmap.Width - destRect.Width, 0, destRect.Width, destRect.Height), GraphicsUnit.Pixel);
                    }
                    else
                    {
                        DataGridViewColumnHeaderCellRenderer.DrawHeader(g, destRect, headerState);
                    }
                }
                Rectangle themeMargins = DataGridViewHeaderCell.GetThemeMargins(g);
                bounds.Y      += themeMargins.Y;
                bounds.Height -= themeMargins.Y + themeMargins.Height;
                if (base.DataGridView.RightToLeftInternal)
                {
                    bounds.X     += themeMargins.Width;
                    bounds.Width -= themeMargins.X + themeMargins.Width;
                }
                else
                {
                    bounds.X     += themeMargins.X;
                    bounds.Width -= themeMargins.X + themeMargins.Width;
                }
            }
            else
            {
                if ((paint && DataGridViewCell.PaintBackground(paintParts)) && ((destRect.Width > 0) && (destRect.Height > 0)))
                {
                    SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
                    if (cachedBrush.Color.A == 0xff)
                    {
                        g.FillRectangle(cachedBrush, destRect);
                    }
                }
                if (cellStyle.Padding != Padding.Empty)
                {
                    if (base.DataGridView.RightToLeftInternal)
                    {
                        bounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                    }
                    else
                    {
                        bounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                    }
                    bounds.Width  -= cellStyle.Padding.Horizontal;
                    bounds.Height -= cellStyle.Padding.Vertical;
                }
            }
            bool   flag2 = false;
            Point  point = new Point(0, 0);
            string str   = formattedValue as string;

            bounds.Y++;
            bounds.Height -= 2;
            if (((((bounds.Width - 2) - 2) > 0) && (bounds.Height > 0)) && !string.IsNullOrEmpty(str))
            {
                Color color;
                bounds.Offset(2, 0);
                bounds.Width -= 4;
                if (base.DataGridView.ApplyVisualStylesToHeaderCells)
                {
                    color = DataGridViewColumnHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                }
                else
                {
                    color = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                }
                if ((base.OwningColumn != null) && (base.OwningColumn.SortMode != DataGridViewColumnSortMode.NotSortable))
                {
                    bool flag3;
                    int  maxWidth = ((bounds.Width - 2) - 9) - 8;
                    if (((maxWidth > 0) && (DataGridViewCell.GetPreferredTextHeight(g, base.DataGridView.RightToLeftInternal, str, cellStyle, maxWidth, out flag3) <= bounds.Height)) && !flag3)
                    {
                        flag2         = this.SortGlyphDirection != SortOrder.None;
                        bounds.Width -= 0x13;
                        if (base.DataGridView.RightToLeftInternal)
                        {
                            bounds.X += 0x13;
                            point     = new Point((((bounds.Left - 2) - 2) - 4) - 9, bounds.Top + ((bounds.Height - 7) / 2));
                        }
                        else
                        {
                            point = new Point(((bounds.Right + 2) + 2) + 4, bounds.Top + ((bounds.Height - 7) / 2));
                        }
                    }
                }
                TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                if (paint)
                {
                    if (DataGridViewCell.PaintContentForeground(paintParts))
                    {
                        if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default)
                        {
                            flags |= TextFormatFlags.EndEllipsis;
                        }
                        TextRenderer.DrawText(g, str, cellStyle.Font, bounds, color, flags);
                    }
                }
                else
                {
                    empty = DataGridViewUtilities.GetTextBounds(bounds, str, flags, cellStyle);
                }
            }
            else if ((paint && (this.SortGlyphDirection != SortOrder.None)) && ((bounds.Width >= 0x11) && (bounds.Height >= 7)))
            {
                flag2 = true;
                point = new Point(bounds.Left + ((bounds.Width - 9) / 2), bounds.Top + ((bounds.Height - 7) / 2));
            }
            if ((paint && flag2) && DataGridViewCell.PaintContentBackground(paintParts))
            {
                Pen darkPen  = null;
                Pen lightPen = null;
                base.GetContrastedPens(cellStyle.BackColor, ref darkPen, ref lightPen);
                if (this.SortGlyphDirection != SortOrder.Ascending)
                {
                    switch (advancedBorderStyle.Right)
                    {
                    case DataGridViewAdvancedCellBorderStyle.Inset:
                        g.DrawLine(lightPen, point.X, point.Y + 1, (point.X + 4) - 1, (point.Y + 7) - 1);
                        g.DrawLine(lightPen, (int)(point.X + 1), (int)(point.Y + 1), (int)((point.X + 4) - 1), (int)((point.Y + 7) - 1));
                        g.DrawLine(darkPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 2), (int)(point.Y + 1));
                        g.DrawLine(darkPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 3), (int)(point.Y + 1));
                        g.DrawLine(darkPen, point.X, point.Y, (point.X + 9) - 2, point.Y);
                        return(empty);

                    case DataGridViewAdvancedCellBorderStyle.Outset:
                    case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
                    case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
                        g.DrawLine(darkPen, point.X, point.Y + 1, (point.X + 4) - 1, (point.Y + 7) - 1);
                        g.DrawLine(darkPen, (int)(point.X + 1), (int)(point.Y + 1), (int)((point.X + 4) - 1), (int)((point.Y + 7) - 1));
                        g.DrawLine(lightPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 2), (int)(point.Y + 1));
                        g.DrawLine(lightPen, (int)(point.X + 4), (int)((point.Y + 7) - 1), (int)((point.X + 9) - 3), (int)(point.Y + 1));
                        g.DrawLine(lightPen, point.X, point.Y, (point.X + 9) - 2, point.Y);
                        return(empty);
                    }
                    for (int j = 0; j < 4; j++)
                    {
                        g.DrawLine(darkPen, (int)(point.X + j), (int)((point.Y + j) + 2), (int)(((point.X + 9) - j) - 1), (int)((point.Y + j) + 2));
                    }
                    g.DrawLine(darkPen, (int)(point.X + 4), (int)((point.Y + 4) + 1), (int)(point.X + 4), (int)((point.Y + 4) + 2));
                    return(empty);
                }
                switch (advancedBorderStyle.Right)
                {
                case DataGridViewAdvancedCellBorderStyle.Inset:
                    g.DrawLine(lightPen, point.X, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y);
                    g.DrawLine(lightPen, point.X + 1, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y);
                    g.DrawLine(darkPen, point.X + 4, point.Y, (point.X + 9) - 2, (point.Y + 7) - 2);
                    g.DrawLine(darkPen, point.X + 4, point.Y, (point.X + 9) - 3, (point.Y + 7) - 2);
                    g.DrawLine(darkPen, point.X, (point.Y + 7) - 1, (point.X + 9) - 2, (point.Y + 7) - 1);
                    return(empty);

                case DataGridViewAdvancedCellBorderStyle.Outset:
                case DataGridViewAdvancedCellBorderStyle.OutsetDouble:
                case DataGridViewAdvancedCellBorderStyle.OutsetPartial:
                    g.DrawLine(darkPen, point.X, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y);
                    g.DrawLine(darkPen, point.X + 1, (point.Y + 7) - 2, (point.X + 4) - 1, point.Y);
                    g.DrawLine(lightPen, point.X + 4, point.Y, (point.X + 9) - 2, (point.Y + 7) - 2);
                    g.DrawLine(lightPen, point.X + 4, point.Y, (point.X + 9) - 3, (point.Y + 7) - 2);
                    g.DrawLine(lightPen, point.X, (point.Y + 7) - 1, (point.X + 9) - 2, (point.Y + 7) - 1);
                    return(empty);
                }
                for (int i = 0; i < 4; i++)
                {
                    g.DrawLine(darkPen, (int)(point.X + i), (int)(((point.Y + 7) - i) - 1), (int)(((point.X + 9) - i) - 1), (int)(((point.Y + 7) - i) - 1));
                }
                g.DrawLine(darkPen, (int)(point.X + 4), (int)(((point.Y + 7) - 4) - 1), (int)(point.X + 4), (int)((point.Y + 7) - 4));
            }
            return(empty);
        }
        private Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint)
        {
            Rectangle empty      = Rectangle.Empty;
            Rectangle bounds     = cellBounds;
            Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle);

            bounds.Offset(rectangle3.X, rectangle3.Y);
            bounds.Width  -= rectangle3.Right;
            bounds.Height -= rectangle3.Bottom;
            bool flag = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;

            if (paint && DataGridViewCell.PaintBackground(paintParts))
            {
                if (base.DataGridView.ApplyVisualStylesToHeaderCells)
                {
                    int headerState = 1;
                    if (base.ButtonState != ButtonState.Normal)
                    {
                        headerState = 3;
                    }
                    else if ((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex))
                    {
                        headerState = 2;
                    }
                    bounds.Inflate(0x10, 0x10);
                    DataGridViewTopLeftHeaderCellRenderer.DrawHeader(graphics, bounds, headerState);
                    bounds.Inflate(-16, -16);
                }
                else
                {
                    SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
                    if (cachedBrush.Color.A == 0xff)
                    {
                        graphics.FillRectangle(cachedBrush, bounds);
                    }
                }
            }
            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            if (cellStyle.Padding != Padding.Empty)
            {
                if (base.DataGridView.RightToLeftInternal)
                {
                    bounds.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    bounds.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                bounds.Width  -= cellStyle.Padding.Horizontal;
                bounds.Height -= cellStyle.Padding.Vertical;
            }
            Rectangle cellValueBounds = bounds;
            string    str             = formattedValue as string;

            bounds.Offset(1, 1);
            bounds.Width  -= 3;
            bounds.Height -= 2;
            if ((((bounds.Width > 0) && (bounds.Height > 0)) && !string.IsNullOrEmpty(str)) && (paint || computeContentBounds))
            {
                Color color;
                if (base.DataGridView.ApplyVisualStylesToHeaderCells)
                {
                    color = DataGridViewTopLeftHeaderCellRenderer.VisualStyleRenderer.GetColor(ColorProperty.TextColor);
                }
                else
                {
                    color = flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor;
                }
                TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                if (paint)
                {
                    if (DataGridViewCell.PaintContentForeground(paintParts))
                    {
                        if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default)
                        {
                            flags |= TextFormatFlags.EndEllipsis;
                        }
                        TextRenderer.DrawText(graphics, str, cellStyle.Font, bounds, color, flags);
                    }
                }
                else
                {
                    empty = DataGridViewUtilities.GetTextBounds(bounds, str, flags, cellStyle);
                }
            }
            else if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText))
            {
                empty = base.ComputeErrorIconBounds(cellValueBounds);
            }
            if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                base.PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
            }
            return(empty);
        }
Exemplo n.º 14
0
        private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint)
        {
            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            Rectangle empty      = Rectangle.Empty;
            Rectangle rectangle2 = this.BorderWidths(advancedBorderStyle);
            Rectangle rect       = cellBounds;

            rect.Offset(rectangle2.X, rectangle2.Y);
            rect.Width  -= rectangle2.Right;
            rect.Height -= rectangle2.Bottom;
            Point      currentCellAddress = base.DataGridView.CurrentCellAddress;
            bool       flag        = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex);
            bool       flag2       = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;
            SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag2) ? cellStyle.SelectionBackColor : cellStyle.BackColor);

            if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
            {
                g.FillRectangle(cachedBrush, rect);
            }
            if (cellStyle.Padding != Padding.Empty)
            {
                if (base.DataGridView.RightToLeftInternal)
                {
                    rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                rect.Width  -= cellStyle.Padding.Horizontal;
                rect.Height -= cellStyle.Padding.Vertical;
            }
            Rectangle rectangle = rect;
            string    text      = formattedValue as string;

            if ((text != null) && (paint || computeContentBounds))
            {
                rect.Offset(1, 1);
                rect.Width  -= 3;
                rect.Height -= 2;
                if ((cellStyle.Alignment & anyBottom) != DataGridViewContentAlignment.NotSet)
                {
                    rect.Height--;
                }
                Font linkFont      = null;
                Font hoverLinkFont = null;
                LinkUtilities.EnsureLinkFonts(cellStyle.Font, this.LinkBehavior, ref linkFont, ref hoverLinkFont);
                TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                if (paint)
                {
                    if ((rect.Width > 0) && (rect.Height > 0))
                    {
                        Color activeLinkColor;
                        if ((flag && base.DataGridView.ShowFocusCues) && (base.DataGridView.Focused && DataGridViewCell.PaintFocus(paintParts)))
                        {
                            Rectangle rectangle5 = DataGridViewUtilities.GetTextBounds(rect, text, flags, cellStyle, (this.LinkState == System.Windows.Forms.LinkState.Hover) ? hoverLinkFont : linkFont);
                            if ((cellStyle.Alignment & anyLeft) != DataGridViewContentAlignment.NotSet)
                            {
                                rectangle5.X--;
                                rectangle5.Width++;
                            }
                            else if ((cellStyle.Alignment & anyRight) != DataGridViewContentAlignment.NotSet)
                            {
                                rectangle5.X++;
                                rectangle5.Width++;
                            }
                            rectangle5.Height += 2;
                            ControlPaint.DrawFocusRectangle(g, rectangle5, Color.Empty, cachedBrush.Color);
                        }
                        if ((this.LinkState & System.Windows.Forms.LinkState.Active) == System.Windows.Forms.LinkState.Active)
                        {
                            activeLinkColor = this.ActiveLinkColor;
                        }
                        else if (this.LinkVisited)
                        {
                            activeLinkColor = this.VisitedLinkColor;
                        }
                        else
                        {
                            activeLinkColor = this.LinkColor;
                        }
                        if (DataGridViewCell.PaintContentForeground(paintParts))
                        {
                            if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.Default)
                            {
                                flags |= TextFormatFlags.EndEllipsis;
                            }
                            TextRenderer.DrawText(g, text, (this.LinkState == System.Windows.Forms.LinkState.Hover) ? hoverLinkFont : linkFont, rect, activeLinkColor, flags);
                        }
                    }
                    else if (((flag && base.DataGridView.ShowFocusCues) && (base.DataGridView.Focused && DataGridViewCell.PaintFocus(paintParts))) && ((rectangle.Width > 0) && (rectangle.Height > 0)))
                    {
                        ControlPaint.DrawFocusRectangle(g, rectangle, Color.Empty, cachedBrush.Color);
                    }
                }
                else
                {
                    empty = DataGridViewUtilities.GetTextBounds(rect, text, flags, cellStyle, (this.LinkState == System.Windows.Forms.LinkState.Hover) ? hoverLinkFont : linkFont);
                }
                linkFont.Dispose();
                hoverLinkFont.Dispose();
            }
            else if (paint || computeContentBounds)
            {
                if (((flag && base.DataGridView.ShowFocusCues) && (base.DataGridView.Focused && DataGridViewCell.PaintFocus(paintParts))) && ((paint && (rect.Width > 0)) && (rect.Height > 0)))
                {
                    ControlPaint.DrawFocusRectangle(g, rect, Color.Empty, cachedBrush.Color);
                }
            }
            else if (computeErrorIconBounds && !string.IsNullOrEmpty(errorText))
            {
                empty = base.ComputeErrorIconBounds(rectangle);
            }
            if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, rectangle, errorText);
            }
            return(empty);
        }
        private Rectangle PaintPrivate(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts, bool computeContentBounds, bool computeErrorIconBounds, bool paint)
        {
            Rectangle  empty;
            Point      currentCellAddress = base.DataGridView.CurrentCellAddress;
            bool       flag        = (elementState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;
            bool       flag2       = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex);
            string     text        = formattedValue as string;
            SolidBrush cachedBrush = base.DataGridView.GetCachedBrush((DataGridViewCell.PaintSelectionBackground(paintParts) && flag) ? cellStyle.SelectionBackColor : cellStyle.BackColor);
            SolidBrush brush2      = base.DataGridView.GetCachedBrush(flag ? cellStyle.SelectionForeColor : cellStyle.ForeColor);

            if (paint && DataGridViewCell.PaintBorder(paintParts))
            {
                this.PaintBorder(g, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            Rectangle rect       = cellBounds;
            Rectangle rectangle3 = this.BorderWidths(advancedBorderStyle);

            rect.Offset(rectangle3.X, rectangle3.Y);
            rect.Width  -= rectangle3.Right;
            rect.Height -= rectangle3.Bottom;
            if ((rect.Height <= 0) || (rect.Width <= 0))
            {
                return(Rectangle.Empty);
            }
            if ((paint && DataGridViewCell.PaintBackground(paintParts)) && (cachedBrush.Color.A == 0xff))
            {
                g.FillRectangle(cachedBrush, rect);
            }
            if (cellStyle.Padding != Padding.Empty)
            {
                if (base.DataGridView.RightToLeftInternal)
                {
                    rect.Offset(cellStyle.Padding.Right, cellStyle.Padding.Top);
                }
                else
                {
                    rect.Offset(cellStyle.Padding.Left, cellStyle.Padding.Top);
                }
                rect.Width  -= cellStyle.Padding.Horizontal;
                rect.Height -= cellStyle.Padding.Vertical;
            }
            Rectangle cellValueBounds = rect;

            if (((rect.Height <= 0) || (rect.Width <= 0)) || (!paint && !computeContentBounds))
            {
                if (computeErrorIconBounds)
                {
                    if (!string.IsNullOrEmpty(errorText))
                    {
                        empty = base.ComputeErrorIconBounds(cellValueBounds);
                    }
                    else
                    {
                        empty = Rectangle.Empty;
                    }
                }
                else
                {
                    empty = Rectangle.Empty;
                }
                goto Label_06AD;
            }
            if ((this.FlatStyle == System.Windows.Forms.FlatStyle.Standard) || (this.FlatStyle == System.Windows.Forms.FlatStyle.System))
            {
                if (base.DataGridView.ApplyVisualStylesToInnerCells)
                {
                    if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                    {
                        PushButtonState normal = PushButtonState.Normal;
                        if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal)
                        {
                            normal = PushButtonState.Pressed;
                        }
                        else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds)
                        {
                            normal = PushButtonState.Hot;
                        }
                        if ((DataGridViewCell.PaintFocus(paintParts) && flag2) && (base.DataGridView.ShowFocusCues && base.DataGridView.Focused))
                        {
                            normal |= PushButtonState.Default;
                        }
                        DataGridViewButtonCellRenderer.DrawButton(g, rect, (int)normal);
                    }
                    empty = rect;
                    rect  = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, rect);
                }
                else
                {
                    if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                    {
                        ControlPaint.DrawBorder(g, rect, SystemColors.Control, (this.ButtonState == System.Windows.Forms.ButtonState.Normal) ? ButtonBorderStyle.Outset : ButtonBorderStyle.Inset);
                    }
                    empty = rect;
                    rect.Inflate(-SystemInformation.Border3DSize.Width, -SystemInformation.Border3DSize.Height);
                }
                goto Label_06AD;
            }
            if (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)
            {
                rect.Inflate(-1, -1);
                if (paint && DataGridViewCell.PaintContentBackground(paintParts))
                {
                    if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal)
                    {
                        ButtonBaseAdapter.ColorData data2 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate();
                        ButtonBaseAdapter.DrawDefaultBorder(g, rect, data2.options.highContrast ? data2.windowText : data2.windowFrame, true);
                        ControlPaint.DrawBorder(g, rect, data2.options.highContrast ? data2.windowText : data2.buttonShadow, ButtonBorderStyle.Solid);
                    }
                    else if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds)
                    {
                        ButtonBaseAdapter.ColorData colors = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate();
                        ButtonBaseAdapter.DrawDefaultBorder(g, rect, colors.options.highContrast ? colors.windowText : colors.buttonShadow, false);
                        ButtonBaseAdapter.Draw3DLiteBorder(g, rect, colors, true);
                    }
                    else
                    {
                        ButtonBaseAdapter.ColorData data4 = ButtonBaseAdapter.PaintPopupRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate();
                        ButtonBaseAdapter.DrawDefaultBorder(g, rect, data4.options.highContrast ? data4.windowText : data4.buttonShadow, false);
                        ButtonBaseAdapter.DrawFlatBorder(g, rect, data4.options.highContrast ? data4.windowText : data4.buttonShadow);
                    }
                }
                empty = rect;
                goto Label_06AD;
            }
            rect.Inflate(-1, -1);
            if (paint && DataGridViewCell.PaintContentBackground(paintParts))
            {
                ButtonBaseAdapter.DrawDefaultBorder(g, rect, brush2.Color, true);
                if (cachedBrush.Color.A == 0xff)
                {
                    if ((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal)
                    {
                        ButtonBaseAdapter.ColorData data = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate();
                        IntPtr hdc = g.GetHdc();
                        try
                        {
                            using (WindowsGraphics graphics = WindowsGraphics.FromHdc(hdc))
                            {
                                WindowsBrush brush3;
                                if (data.options.highContrast)
                                {
                                    brush3 = new WindowsSolidBrush(graphics.DeviceContext, data.buttonShadow);
                                }
                                else
                                {
                                    brush3 = new WindowsSolidBrush(graphics.DeviceContext, data.lowHighlight);
                                }
                                try
                                {
                                    ButtonBaseAdapter.PaintButtonBackground(graphics, rect, brush3);
                                }
                                finally
                                {
                                    brush3.Dispose();
                                }
                            }
                            goto Label_04CF;
                        }
                        finally
                        {
                            g.ReleaseHdc();
                        }
                    }
                    if (((base.DataGridView.MouseEnteredCellAddress.Y == rowIndex) && (base.DataGridView.MouseEnteredCellAddress.X == base.ColumnIndex)) && mouseInContentBounds)
                    {
                        IntPtr hDc = g.GetHdc();
                        try
                        {
                            using (WindowsGraphics graphics2 = WindowsGraphics.FromHdc(hDc))
                            {
                                Color controlDark = SystemColors.ControlDark;
                                using (WindowsBrush brush4 = new WindowsSolidBrush(graphics2.DeviceContext, controlDark))
                                {
                                    ButtonBaseAdapter.PaintButtonBackground(graphics2, rect, brush4);
                                }
                            }
                        }
                        finally
                        {
                            g.ReleaseHdc();
                        }
                    }
                }
            }
Label_04CF:
            empty = rect;
Label_06AD:
            if (((paint && DataGridViewCell.PaintFocus(paintParts)) && (flag2 && base.DataGridView.ShowFocusCues)) && ((base.DataGridView.Focused && (rect.Width > ((2 * SystemInformation.Border3DSize.Width) + 1))) && (rect.Height > ((2 * SystemInformation.Border3DSize.Height) + 1))))
            {
                if ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard))
                {
                    ControlPaint.DrawFocusRectangle(g, Rectangle.Inflate(rect, -1, -1), Color.Empty, SystemColors.Control);
                }
                else if (this.FlatStyle == System.Windows.Forms.FlatStyle.Flat)
                {
                    if (((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) || ((base.DataGridView.CurrentCellAddress.Y == rowIndex) && (base.DataGridView.CurrentCellAddress.X == base.ColumnIndex)))
                    {
                        ButtonBaseAdapter.ColorData data5 = ButtonBaseAdapter.PaintFlatRender(g, cellStyle.ForeColor, cellStyle.BackColor, base.DataGridView.Enabled).Calculate();
                        string str2 = (text != null) ? text : string.Empty;
                        ButtonBaseAdapter.LayoutOptions options = ButtonFlatAdapter.PaintFlatLayout(g, true, SystemInformation.HighContrast, 1, rect, Padding.Empty, false, cellStyle.Font, str2, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft);
                        options.everettButtonCompat = false;
                        ButtonBaseAdapter.LayoutData data6 = options.Layout();
                        ButtonBaseAdapter.DrawFlatFocus(g, data6.focus, data5.options.highContrast ? data5.windowText : data5.constrastButtonShadow);
                    }
                }
                else if (((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) || ((base.DataGridView.CurrentCellAddress.Y == rowIndex) && (base.DataGridView.CurrentCellAddress.X == base.ColumnIndex)))
                {
                    bool   up   = this.ButtonState == System.Windows.Forms.ButtonState.Normal;
                    string str3 = (text != null) ? text : string.Empty;
                    ButtonBaseAdapter.LayoutOptions options2 = ButtonPopupAdapter.PaintPopupLayout(g, up, SystemInformation.HighContrast ? 2 : 1, rect, Padding.Empty, false, cellStyle.Font, str3, base.DataGridView.Enabled, DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment), base.DataGridView.RightToLeft);
                    options2.everettButtonCompat = false;
                    ButtonBaseAdapter.LayoutData data7 = options2.Layout();
                    ControlPaint.DrawFocusRectangle(g, data7.focus, cellStyle.ForeColor, cellStyle.BackColor);
                }
            }
            if (((text != null) && paint) && DataGridViewCell.PaintContentForeground(paintParts))
            {
                rect.Offset(2, 1);
                rect.Width  -= 4;
                rect.Height -= 2;
                if ((((this.ButtonState & (System.Windows.Forms.ButtonState.Checked | System.Windows.Forms.ButtonState.Pushed)) != System.Windows.Forms.ButtonState.Normal) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Flat)) && (this.FlatStyle != System.Windows.Forms.FlatStyle.Popup))
                {
                    rect.Offset(1, 1);
                    rect.Width--;
                    rect.Height--;
                }
                if ((rect.Width > 0) && (rect.Height > 0))
                {
                    Color color;
                    if (base.DataGridView.ApplyVisualStylesToInnerCells && ((this.FlatStyle == System.Windows.Forms.FlatStyle.System) || (this.FlatStyle == System.Windows.Forms.FlatStyle.Standard)))
                    {
                        color = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetColor(ColorProperty.TextColor);
                    }
                    else
                    {
                        color = brush2.Color;
                    }
                    TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                    TextRenderer.DrawText(g, text, cellStyle.Font, rect, color, flags);
                }
            }
            if ((base.DataGridView.ShowCellErrors && paint) && DataGridViewCell.PaintErrorIcon(paintParts))
            {
                base.PaintErrorIcon(g, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
            }
            return(empty);
        }