protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     var buttonRectangle = new Rectangle(cellBounds.X + 2, cellBounds.Y + 2, cellBounds.Width - 4, cellBounds.Height - 4);
     base.Paint(graphics, clipBounds, buttonRectangle, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     var imageRectangle = new Rectangle(cellBounds.X + 6, cellBounds.Y + 6, _detailImage.Width, _detailImage.Height);
     graphics.DrawImage(_detailImage, imageRectangle);
 }
Example #2
0
        protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            int progressVal = 0;
            string label = String.Empty;

            // get progress values
            if (value != null && value.GetType() == typeof(ProgressState))
            {
                ProgressState s = (ProgressState)value;
                progressVal = s.CurrentValue;
                label = s.CurrentState;
                if (s.ShowProgressBar == false || String.IsNullOrEmpty(label) == false)
                    progressVal = 0;
                if (s.HasError)
                    this.ErrorText = s.ErrorText;
            }

            // Draws the cell grid
            base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

            // draw progress bar
            float percentage = ((float)progressVal / 100.0f); // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%.
            if (percentage > 0.0)
            {
                using (Brush highlightBrush = new SolidBrush(SystemColors.Highlight))
                    g.FillRectangle(highlightBrush, cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);
            }

            // draw text
            if (String.IsNullOrEmpty(label) == false)
            {
                using (Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor))
                    g.DrawString(label, cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 4);
            }
        }
        protected override void Paint(
            Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates cellState,
            object value,
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // Call the base class method to paint the default cell appearance.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                value, formattedValue, errorText, cellStyle,
                advancedBorderStyle, paintParts);

            // Retrieve the client location of the mouse pointer.
            Point cursorPosition =
                this.DataGridView.PointToClient(Cursor.Position);

            // If the mouse pointer is over the current cell, draw a custom border.
            if (cellBounds.Contains(cursorPosition))
            {
                Rectangle newRect = new Rectangle(cellBounds.X + 1,
                    cellBounds.Y + 1, cellBounds.Width - 4,
                    cellBounds.Height - 4);
                graphics.DrawRectangle(Pens.Red, newRect);
            }
        }
 public DataGridViewCellPaintingEventArgs(DataGridView dataGridView, System.Drawing.Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     if (dataGridView == null)
     {
         throw new ArgumentNullException("dataGridView");
     }
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (cellStyle == null)
     {
         throw new ArgumentNullException("cellStyle");
     }
     if ((paintParts & ~DataGridViewPaintParts.All) != DataGridViewPaintParts.None)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("DataGridView_InvalidDataGridViewPaintPartsCombination", new object[] { "paintParts" }));
     }
     this.graphics = graphics;
     this.clipBounds = clipBounds;
     this.cellBounds = cellBounds;
     this.rowIndex = rowIndex;
     this.columnIndex = columnIndex;
     this.cellState = cellState;
     this.value = value;
     this.formattedValue = formattedValue;
     this.errorText = errorText;
     this.cellStyle = cellStyle;
     this.advancedBorderStyle = advancedBorderStyle;
     this.paintParts = paintParts;
 }
        //绘制列头checkbox
        protected override void Paint(System.Drawing.Graphics graphics,
                                      System.Drawing.Rectangle clipBounds,
                                      System.Drawing.Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates dataGridViewElementState,
                                      object value,
                                      object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                        dataGridViewElementState, value,
                        formattedValue, errorText, cellStyle,
                        advancedBorderStyle, paintParts);

            Point p = new Point();
            Size s = CheckBoxRenderer.GetGlyphSize(graphics,
            System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
            p.X = cellBounds.Location.X + (cellBounds.Width / 2) - (s.Width / 2) - 1;//列头checkbox的X坐标
            p.Y = cellBounds.Location.Y + (cellBounds.Height / 2) - (s.Height / 2);//列头checkbox的Y坐标
            _cellLocation = cellBounds.Location;
            checkBoxLocation = p;
            checkBoxSize = s;
            if (_checked)
                _cbState = CheckBoxState.CheckedNormal;
            else
                _cbState = CheckBoxState.UncheckedNormal;
            CheckBoxRenderer.DrawCheckBox(graphics, checkBoxLocation, _cbState);
        }
    protected override void Paint(Graphics graphics, Rectangle clipBounds,
        Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
        object value, object formattedValue, string errorText,
        DataGridViewCellStyle cellStyle,
        DataGridViewAdvancedBorderStyle advancedBorderStyle,
        DataGridViewPaintParts paintParts)
    {
      if (Columns.Count > rowIndex)
      {
        Column c = Columns[rowIndex];
        if (c.PrimaryKey)
        {
          Bitmap bmp = rowIndex == DataGridView.CurrentRow.Index ?
              Resources.ArrowKey : Resources.Key;
          bmp.MakeTransparent();
          paintParts &= ~DataGridViewPaintParts.ContentBackground;
          base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
              value, formattedValue, errorText, cellStyle, advancedBorderStyle,
              paintParts);
          Rectangle r = cellBounds;
          r.Offset(bmp.Width / 2, bmp.Height / 2);
          r.Width = bmp.Width;
          r.Height = bmp.Height;
          graphics.DrawImage(bmp, r);
          return;
        }
      }

      base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
          value, formattedValue, errorText, cellStyle, advancedBorderStyle,
          paintParts);
    }
        protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates cellState, object value, object formattedValue,
            string errorText, DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            int progressVal = 0;
              if (value != null)
            progressVal = (int)value;

              float percentage = (progressVal / 100.0f);
            // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%.
              Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
              Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
              // Draws the cell grid
              base.Paint(g, clipBounds, cellBounds,
                 rowIndex, cellState, value, formattedValue, errorText,
                 cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
              if (percentage > 0.0)
              {
            // Draw the progress bar and the text
            g.FillRectangle(new SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2,
                        Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);
            g.DrawString(progressVal + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
              }
              else
              {
            // draw the text
            if (DataGridView.CurrentRow.Index == rowIndex)
              g.DrawString(progressVal + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6,
                       cellBounds.Y + 2);
            else
              g.DrawString(progressVal + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
              }
        }
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                string text = value == null ? "" : (string)value;
                Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
                Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
                var col = this.OwningColumn as DataGridViewColorMarkColumn;
                Color markcolor = cellStyle.ForeColor;
                bool hasmark = col.GetColorMark(rowIndex, out markcolor);
                Brush markColorBrush = new SolidBrush(markcolor);

                base.Paint(g, clipBounds, cellBounds,
                    rowIndex, cellState, value, formattedValue, errorText,
                    cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

                int rsz = this.DataGridView.RowTemplate.Height - 8;
                int dy = (cellBounds.Height - this.DataGridView.RowTemplate.Height) / 2;

                g.FillEllipse(markColorBrush, cellBounds.X + 2, cellBounds.Y + 4 + dy, rsz, rsz);
                //g.FillRectangle(markColorBrush, cellBounds.X + 2, cellBounds.Y + 4, rsz, rsz);
                g.DrawString(text, cellStyle.Font, foreColorBrush, cellBounds.X + 4 + rsz, cellBounds.Y + 2 + dy);
            }
            catch (Exception e) { }
        }
Example #9
0
        protected override void Paint(Graphics graphics,
            Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates elementState, object value,
            object formattedValue, string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // The button cell is disabled, so paint the border,
            // background, and disabled button for the cell.
            if (!this.enabledValue)
            {
                // Draw the cell background, if specified.
                if ((paintParts & DataGridViewPaintParts.Background) ==
                    DataGridViewPaintParts.Background)
                {
                    SolidBrush cellBackground =
                    new SolidBrush(cellStyle.BackColor);
                    graphics.FillRectangle(cellBackground, cellBounds);
                    cellBackground.Dispose();
                }

                // Draw the cell borders, if specified.
                if ((paintParts & DataGridViewPaintParts.Border) ==
                    DataGridViewPaintParts.Border)
                {
                    PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
                        advancedBorderStyle);
                }

                // Calculate the area in which to draw the button.
                Rectangle buttonArea = cellBounds;
                Rectangle buttonAdjustment =
                    this.BorderWidths(advancedBorderStyle);
                buttonArea.X += buttonAdjustment.X;
                buttonArea.Y += buttonAdjustment.Y;
                buttonArea.Height -= buttonAdjustment.Height;
                buttonArea.Width -= buttonAdjustment.Width;

                // Draw the disabled button.
                ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled);

                // Draw the disabled button text.
                if (this.FormattedValue is String)
                {
                    TextRenderer.DrawText(graphics,
                        (string)this.FormattedValue,
                        this.DataGridView.Font,
                        buttonArea, enabledValue ? SystemColors.ControlText : SystemColors.GrayText);
                }
            }
            else
            {
                // The button cell is enabled, so let the base class
                // handle the painting.
                base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                    elementState, value, formattedValue, errorText,
                   cellStyle, advancedBorderStyle, paintParts);
            }
        }
        protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                int progressVal = (int)value;
                float percentage = ((float)progressVal / 100.0f); // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%.

                // Draws the cell grid
                base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

                // Draw the progress bar and the text
                g.FillRectangle(new SolidBrush(Color.FromArgb(8, 142, 6)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);

                string text = Value.ToString() + "%";
                Font f = cellStyle.Font;

                SizeF len = g.MeasureString(text, f);

                SolidBrush foreColor = new SolidBrush(cellStyle.ForeColor);

                if (DataGridView.Rows[rowIndex].Selected)
                    foreColor = new SolidBrush(cellStyle.SelectionForeColor);

                Point location = new Point(Convert.ToInt32(cellBounds.X + ((cellBounds.Width / 2) - len.Width / 2)), Convert.ToInt32(cellBounds.Y + ((cellBounds.Height / 2) - len.Height / 2)));
                g.DrawString(text, f, foreColor, location);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Error painting cell");
            }
        }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            var fillRectangle = new Rectangle(cellBounds.X, cellBounds.Y, cellBounds.Width - 1, cellBounds.Height - 1);
            var stringRectangle = new Rectangle(cellBounds.X + 5, cellBounds.Y + 3, cellBounds.Width - 8, cellBounds.Height - 8);
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.FillRectangle(new SolidBrush(Color.FromArgb(215, 228, 242)),
                                   fillRectangle);
            graphics.DrawLine(new Pen(Color.FromArgb(153, 180, 209), 1),
                              new Point(cellBounds.X + cellBounds.Width - 1, cellBounds.Y),
                              new Point(cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1));
            graphics.DrawLine(new Pen(Color.FromArgb(153, 180, 209), 1),
                              new Point(cellBounds.X, cellBounds.Y + cellBounds.Height - 1),
                              new Point(cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1));
            //var pen = new Pen(new LinearGradientBrush(new Rectangle(1, 1, 1, 1), 
            //                  Color.FromArgb(0, 0, 0), 
            //                  Color.FromArgb(200, 200, 200), 
            //                  LinearGradientMode.Horizontal))
            //{
            //    DashCap = DashCap.Round,
            //    Width = 1
            //};

            //graphics.DrawLine(pen,
            //                 new Point(cellBounds.X + 7, cellBounds.Y + 7),
            //                 new Point(cellBounds.X + cellBounds.Width - 7, cellBounds.Y + cellBounds.Height - 7));
            //graphics.DrawLine(pen,
            //                 new Point(cellBounds.X + cellBounds.Width - 7, cellBounds.Y + 7),
            //                 new Point(cellBounds.X + 7, cellBounds.Y + cellBounds.Height - 7));
            graphics.DrawString("X",
                                new Font("Comic Sans MS", 9.0f, FontStyle.Regular),
                                new SolidBrush(Color.FromArgb(0, 0, 0)),
                                stringRectangle);
        }
Example #12
0
			protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
				DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText,
				DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
				DataGridViewPaintParts paintParts) {
				graphics.FillRectangle(new SolidBrush(SystemColors.Control), cellBounds);
				if (DataGridView.SelectedCells.Count > 0 &&
				    (DataGridView.SelectedCells[0].ColumnIndex == ColumnIndex ||
				     DataGridView.SelectedCells[0].RowIndex == RowIndex)) {
					ControlPaint.DrawBorder(graphics, cellBounds,
						SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid,
						SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid,
						SystemColors.ButtonFace, 1, ButtonBorderStyle.Solid,
						SystemColors.ButtonFace, 1, ButtonBorderStyle.Solid);
				}
				else {
					ControlPaint.DrawBorder(graphics, cellBounds,
						SystemColors.ButtonHighlight, 1, ButtonBorderStyle.Solid,
						SystemColors.ButtonHighlight, 1, ButtonBorderStyle.Solid,
						SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid,
						SystemColors.ControlDarkDark, 1, ButtonBorderStyle.Solid);

					graphics.DrawLine(SystemPens.ButtonFace,
						cellBounds.Left, cellBounds.Bottom,
						cellBounds.Left, cellBounds.Bottom);
				}

				var bounds = cellBounds;
				bounds.Inflate(-2, -2);
				TextRenderer.DrawText(graphics, (string)formattedValue, cellStyle.Font, bounds,
					cellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Left);
			}
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            // the base Paint implementation paints the check box
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            // Get the check box bounds: they are the content bounds
            Rectangle contentBounds = this.GetContentBounds(rowIndex);

            // Compute the location where we want to paint the string.
            Point stringLocation = new Point();

            // Compute the Y.
            // NOTE: the current logic does not take into account padding.
            stringLocation.Y = cellBounds.Y + 2;

            // Compute the X.
            // Content bounds are computed relative to the cell bounds
            // - not relative to the DataGridView control.
            stringLocation.X = cellBounds.X + contentBounds.Right + 2;

            // Paint the string.
            if (this.Label == null)
            {
                DataGridViewCheckBoxWithLabelColumn col = (DataGridViewCheckBoxWithLabelColumn) this.OwningColumn;
                this.label = col.Label;
            }

            graphics.DrawString(this.Label, Control.DefaultFont, System.Drawing.Brushes.Red, stringLocation);
        }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            if (Image != null)
            {
                base.Paint(graphics, clipBounds,
                           new Rectangle(cellBounds.X + Image.Width, cellBounds.Y, cellBounds.Width - Image.Height,cellBounds.Height),
                           rowIndex, cellState, value, formattedValue,errorText, cellStyle, advancedBorderStyle, paintParts);

                if ((cellState & DataGridViewElementStates.Selected) != 0)
                {
                    graphics.FillRectangle(
                        new SolidBrush(this.DataGridView.DefaultCellStyle.SelectionBackColor)
                        , cellBounds.X, cellBounds.Y, Image.Width, cellBounds.Height);
                }
                else
                {
                    graphics.FillRectangle(new SolidBrush(this.DataGridView.DefaultCellStyle.BackColor),
                                           cellBounds.X, cellBounds.Y, Image.Width, cellBounds.Height);
                }
                graphics.DrawImage(Image, cellBounds.X, cellBounds.Y+2, Image.Width,
                                         Math.Min(Image.Height,cellBounds.Height));

            }
            else
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
        }
 /// <include file='doc\DataGridViewRowPrePaintEventArgs.uex' path='docs/doc[@for="DataGridViewRowPrePaintEventArgs.DataGridViewRowPrePaintEventArgs"]/*' />
 public DataGridViewRowPrePaintEventArgs(DataGridView dataGridView,
                                         Graphics graphics, 
                                         Rectangle clipBounds, 
                                         Rectangle rowBounds,
                                         int rowIndex,
                                         DataGridViewElementStates rowState,
                                         string errorText,
                                         DataGridViewCellStyle inheritedRowStyle,
                                         bool isFirstDisplayedRow,
                                         bool isLastVisibleRow)
 {
     if (dataGridView == null)
     {
         throw new ArgumentNullException("dataGridView");
     }
     if (graphics == null)
     {
         throw new ArgumentNullException("graphics");
     }
     if (inheritedRowStyle == null)
     {
         throw new ArgumentNullException("inheritedRowStyle");
     }
     this.dataGridView = dataGridView;
     this.graphics = graphics;
     this.clipBounds = clipBounds;
     this.rowBounds = rowBounds;
     this.rowIndex = rowIndex;
     this.rowState = rowState;
     this.errorText = errorText;
     this.inheritedRowStyle = inheritedRowStyle;
     this.isFirstDisplayedRow = isFirstDisplayedRow;
     this.isLastVisibleRow = isLastVisibleRow;
     this.paintParts = DataGridViewPaintParts.All;
 }
Example #16
0
        protected override void Paint(Graphics graphics,
            Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates dataGridViewElementState,
            object value, object formattedValue, string errorText,
            DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value,
                formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            graphics.FillRectangle(new SolidBrush(cellStyle.BackColor), cellBounds);

            CheckBoxRegion = new Rectangle(
                cellBounds.Location.X + 1,
                cellBounds.Location.Y + 2,
                25, cellBounds.Size.Height - 4);


            if (this.checkAll)
                ControlPaint.DrawCheckBox(graphics, CheckBoxRegion, ButtonState.Checked);
            else
                ControlPaint.DrawCheckBox(graphics, CheckBoxRegion, ButtonState.Normal);

            Rectangle normalRegion =
                new Rectangle(
                cellBounds.Location.X + 1 + 25,
                cellBounds.Location.Y,
                cellBounds.Size.Width - 26,
                cellBounds.Size.Height);

            graphics.DrawString(value.ToString(), cellStyle.Font, new SolidBrush(cellStyle.ForeColor), normalRegion);

        }
Example #17
0
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                int progressVal = (int)value;
                float percentage = ((float)progressVal / 100.0f); // Need to convert to float before division; otherwise C# returns int which is 0 for anything but 100%.
                Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
                Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
                // Draws the cell grid
                base.Paint(g, clipBounds, cellBounds,
                 rowIndex, cellState, value, formattedValue, errorText,
                 cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
                if (percentage > 0.0)
                {
                    // Draw the progress bar and the text
                    g.FillRectangle(new SolidBrush(Color.FromArgb(203, 235, 108)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);
                    g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreColorBrush, cellBounds.X + (cellBounds.Width / 2) - 5, cellBounds.Y + 2);

                }
                else
                {
                    g.DrawString("Ожидание...", cellStyle.Font, foreColorBrush, cellBounds.X + (cellBounds.Width / 2) - 25, cellBounds.Y + 2);
                }
            }
            catch (Exception e) { }
        }
        protected override void Paint(Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates cellState,
            object value,
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            if (this.DataGridView == null)
            {
                return;
            }

            // First paint the borders and background of the cell.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle,
                       paintParts & ~(DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.ContentForeground));

            IRulesBoxLine myLine = Value as IRulesBoxLine;
            myLine.Selected = this.Selected;
            myLine.Paint(graphics, cellStyle.Font, cellBounds.Left, cellBounds.Top);
        }
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                int progressVal = (int)value;
                if(progressVal < 0) progressVal = 0;
                if(progressVal > 100) progressVal = 100;
                float percentage = ((float)progressVal / 100.0f);

                Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
                Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);
                Brush barColorBrush = new SolidBrush(GetColorBetween(cellStyle.BackColor,
                    cellStyle.ForeColor, progressVal == 100 ? 0.2f : 0.3f));

                base.Paint(g, clipBounds, cellBounds,
                    rowIndex, cellState, value, formattedValue, errorText,
                    cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

                var s = progressVal.ToString() + "%";
                var sz = g.MeasureString(s, cellStyle.Font);
                int dy = (cellBounds.Height - this.DataGridView.RowTemplate.Height) / 2;

                g.FillRectangle(barColorBrush, cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4);
                g.DrawString(s, cellStyle.Font, foreColorBrush, cellBounds.X + (cellBounds.Width / 2) - sz.Width / 2 - 5, cellBounds.Y + 2 + dy);
            }
            catch (Exception e) { }
        }
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) {
     if(this.fNowCalculating) {
         this.PaintBackGround(graphics, advancedBorderStyle, cellStyle, cellBounds);
         paintParts &= ~(DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.Background);
     }
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
 }
Example #21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// </summary>
		/// <param name="graphics">The <see cref="T:System.Drawing.Graphics"/> used to paint
		/// the <see cref="T:System.Windows.Forms.DataGridViewCell"/>.</param>
		/// <param name="clipBounds">A <see cref="T:System.Drawing.Rectangle"/> that represents
		/// the area of the <see cref="T:System.Windows.Forms.DataGridView"/> that needs to be
		/// repainted.</param>
		/// <param name="cellBounds">A <see cref="T:System.Drawing.Rectangle"/> that contains
		/// the bounds of the <see cref="T:System.Windows.Forms.DataGridViewCell"/> that is
		/// being painted.</param>
		/// <param name="rowIndex">The row index of the cell that is being painted.</param>
		/// <param name="elementState"></param>
		/// <param name="value">The data of the <see cref="T:System.Windows.Forms.DataGridViewCell"/>
		/// that is being painted.</param>
		/// <param name="formattedValue">The formatted data of the
		/// <see cref="T:System.Windows.Forms.DataGridViewCell"/> that is being painted.</param>
		/// <param name="errorText">An error message that is associated with the cell.</param>
		/// <param name="cellStyle">A <see cref="T:System.Windows.Forms.DataGridViewCellStyle"/>
		/// that contains formatting and style information about the cell.</param>
		/// <param name="advancedBorderStyle">A
		/// <see cref="T:System.Windows.Forms.DataGridViewAdvancedBorderStyle"/> that contains
		/// border styles for the cell that is being painted.</param>
		/// <param name="paintParts">A bitwise combination of the
		/// <see cref="T:System.Windows.Forms.DataGridViewPaintParts"/> values that specifies
		/// which parts of the cell need to be painted.</param>
		/// ------------------------------------------------------------------------------------
		protected override void Paint(Graphics graphics, Rectangle clipBounds,
			Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
			object value, object formattedValue, string errorText,
			DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
			DataGridViewPaintParts paintParts)
		{
			Bitmap bitmap = formattedValue as Bitmap;
			if (bitmap == null || !(OwningColumn is CheckGridStatusColumn))
			{
				// We don't know enough to paint this cell, so we let the base class handle it.
				base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value,
					formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
				return;
			}

			// Let base class paint everything except content
			base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value,
				formattedValue, errorText, cellStyle, advancedBorderStyle,
				paintParts & ~(DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.Background));

			Rectangle cellValueBounds = cellBounds;
			Rectangle borderRect = BorderWidths(advancedBorderStyle);
			cellValueBounds.Offset(borderRect.X, borderRect.Y);
			cellValueBounds.Width -= borderRect.Right;
			cellValueBounds.Height -= borderRect.Bottom;
			if (cellValueBounds.Width <= 0 || cellValueBounds.Height <= 0)
				return;

			if ((paintParts & DataGridViewPaintParts.Background) != 0)
			{
				bool fSelected = (elementState & DataGridViewElementStates.Selected) != 0;
				Color color = (fSelected & (paintParts & DataGridViewPaintParts.SelectionBackground) != 0) ?
					cellStyle.SelectionBackColor : cellStyle.BackColor;
				graphics.FillRectangle(GetCachedBrush(color), cellValueBounds);
			}

			if ((paintParts & DataGridViewPaintParts.ContentForeground) != 0)
			{
				// scale the image according to zoom factor
				float zoomFactor = ((CheckGridStatusColumn)OwningColumn).ZoomFactor;

				int zoomedImageWidth = (int)(bitmap.Width * zoomFactor);
				int zoomedImageHeight = (int)(bitmap.Height * zoomFactor);
				Rectangle drawRect = new Rectangle(
					cellValueBounds.X + (cellValueBounds.Width - zoomedImageWidth) / 2,
					cellValueBounds.Y + (cellValueBounds.Height - zoomedImageHeight) / 2,
					zoomedImageWidth, zoomedImageHeight);

				Region clip = graphics.Clip;
				graphics.SetClip(Rectangle.Intersect(Rectangle.Intersect(drawRect, cellValueBounds),
					Rectangle.Truncate(graphics.VisibleClipBounds)));
				graphics.DrawImage(bitmap, drawRect);
				graphics.Clip = clip;

				ICornerGlyphGrid owningGrid = DataGridView as ICornerGlyphGrid;
				if (owningGrid != null && owningGrid.ShouldDrawCornerGlyph(ColumnIndex, rowIndex))
					DrawCornerGlyph(graphics, rowIndex, cellBounds);
			}
		}
 public void PaintCells(Rectangle clipBounds, DataGridViewPaintParts paintParts)
 {
     if ((this.rowIndex < 0) || (this.rowIndex >= this.dataGridView.Rows.Count))
     {
         throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridViewElementPaintingEventArgs_RowIndexOutOfRange"));
     }
     this.dataGridView.Rows.SharedRow(this.rowIndex).PaintCells(this.graphics, clipBounds, this.rowBounds, this.rowIndex, this.rowState, this.isFirstDisplayedRow, this.isLastVisibleRow, paintParts);
 }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            if (!this.enabledValue)
            {
                // Draw the cell background, if specified.
                if ((paintParts & DataGridViewPaintParts.Background) ==
                    DataGridViewPaintParts.Background)
                {
                    SolidBrush cellBackground =
                        new SolidBrush(cellStyle.BackColor);
                    graphics.FillRectangle(cellBackground, cellBounds);
                    cellBackground.Dispose();
                }

                // Draw the cell borders, if specified.
                if ((paintParts & DataGridViewPaintParts.Border) ==
                    DataGridViewPaintParts.Border)
                {
                    PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
                        advancedBorderStyle);
                }

                // Calculate the area in which to draw the button.
                Rectangle buttonArea = cellBounds;
                Rectangle buttonAdjustment =
                    this.BorderWidths(advancedBorderStyle);
                buttonArea.X += buttonAdjustment.X;
                buttonArea.Y += buttonAdjustment.Y;
                buttonArea.Height -= buttonAdjustment.Height;
                buttonArea.Width -= buttonAdjustment.Width;

                // Draw the disabled button.                
                ButtonRenderer.DrawButton(graphics, buttonArea,
                    PushButtonState.Disabled);

                // Draw the disabled button text. 
                if (this.FormattedValue != null && this.FormattedValue is String)
                {
                    TextRenderer.DrawText(graphics,
                        (string)this.FormattedValue,
                        this.DataGridView.Font,
                        buttonArea, SystemColors.GrayText);
                }
            }
            else
            {
                System.Reflection.Assembly thisExe = System.Reflection.Assembly.GetExecutingAssembly();
                System.IO.Stream file;
                file = thisExe.GetManifestResourceStream("BiologyDepartment.Misc_Files.images.editicon16.png");
                ImageList imgList = new ImageList();
                imgList.ImageSize = new System.Drawing.Size(16, 16);
                imgList.Images.Add(Image.FromStream(file));
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
                graphics.DrawImage(imgList.Images[0], cellBounds);
            }
        }
 /// <summary>
 /// 重写样式
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="clipBounds"></param>
 /// <param name="cellBounds"></param>
 /// <param name="rowIndex"></param>
 /// <param name="cellState"></param>
 /// <param name="value"></param>
 /// <param name="formattedValue"></param>
 /// <param name="errorText"></param>
 /// <param name="cellStyle"></param>
 /// <param name="advancedBorderStyle"></param>
 /// <param name="paintParts"></param>
 protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     //Point cursorPositon = this.DataGridView.PointToClient(Cursor.Position);
     //if (cellBounds.Contains(cursorPositon))
     //{
     //    Rectangle newRect = new Rectangle(cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 4, cellBounds.Height - 4);
     //    graphics.DrawRectangle(Pens.Red, newRect);
     //}
 }
 protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     Point cursorPos = this.DataGridView.PointToClient(Cursor.Position);
     //if (cellBounds.Contains(cursorPos))
     if (Selected)
         base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     else
     {
         graphics.FillRectangle(Brushes.LightGray, cellBounds);
     }
 }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
            DataGridViewElementStates elementState, [CanBeNull] object value, [CanBeNull] object formattedValue,
            [CanBeNull] string errorText, DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            Guard.NotNull(graphics, nameof(graphics));
            Guard.NotNull(cellStyle, nameof(cellStyle));
            Guard.NotNull(advancedBorderStyle, nameof(advancedBorderStyle));

            if (!Enabled)
            {
                if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
                {
                    using (var cellBackground = new SolidBrush(cellStyle.BackColor))
                    {
                        graphics.FillRectangle(cellBackground, cellBounds);
                    }
                }

                if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
                {
                    PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
                }

                Rectangle buttonArea = cellBounds;
                Rectangle buttonAdjustment = BorderWidths(advancedBorderStyle);
                buttonArea.X += buttonAdjustment.X;
                buttonArea.Y += buttonAdjustment.Y;
                buttonArea.Height -= buttonAdjustment.Height;
                buttonArea.Width -= buttonAdjustment.Width;

                // Bug workaround: designer-made changes are not propagated to the incoming advancedBorderStyle here.
                // So correct for padding manually.
                Rectangle contentRect = GetContentBounds(graphics, cellStyle, rowIndex);
                buttonArea.X += contentRect.X;
                buttonArea.Y += contentRect.Y;
                buttonArea.Height = contentRect.Height;
                buttonArea.Width = contentRect.Width;

                ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled);

                string buttonText = FormattedValue as string;
                if (buttonText != null)
                {
                    TextRenderer.DrawText(graphics, buttonText, DataGridView.Font, buttonArea, SystemColors.GrayText);
                }
            }
            else
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText,
                    cellStyle, advancedBorderStyle, paintParts);
            }
        }
 public void Paint(Rectangle clipBounds, DataGridViewPaintParts paintParts)
 {
     if ((this.rowIndex < -1) || (this.rowIndex >= this.dataGridView.Rows.Count))
     {
         throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridViewElementPaintingEventArgs_RowIndexOutOfRange"));
     }
     if ((this.columnIndex < -1) || (this.columnIndex >= this.dataGridView.Columns.Count))
     {
         throw new InvalidOperationException(System.Windows.Forms.SR.GetString("DataGridViewElementPaintingEventArgs_ColumnIndexOutOfRange"));
     }
     this.dataGridView.GetCellInternal(this.columnIndex, this.rowIndex).PaintInternal(this.graphics, clipBounds, this.cellBounds, this.rowIndex, this.cellState, this.value, this.formattedValue, this.errorText, this.cellStyle, this.advancedBorderStyle, paintParts);
 }
Example #28
0
			protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
				DataGridViewElementStates cellState, object value, object formattedValue, string errorText,
				DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
				DataGridViewPaintParts paintParts) {
				base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle,
					advancedBorderStyle, paintParts);
				if (DataGridView.SelectedCells.Count > 0 && DataGridView.SelectedCells[0] == this) {
					var bounds = cellBounds;
					bounds.Width--;
					bounds.Height--;
					ControlPaint.DrawBorder(graphics, bounds, SystemColors.ControlText, ButtonBorderStyle.Solid);
				}
			}
        protected override void Paint( System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts )
        {
            base.Paint( graphics, clipBounds, cellBounds, rowIndex, elementState, null, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts & ~DataGridViewPaintParts.ContentForeground & ~DataGridViewPaintParts.SelectionBackground );

            if ( value != null )
            {
                Image image = (Image) value;
                RectangleF destRect = new RectangleF( cellBounds.Left, cellBounds.Top, 48, 48 );
                RectangleF srcRect = new RectangleF( -0.5f, -0.5f, image.Width, image.Height );
                graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                graphics.DrawImage( image, destRect, srcRect, GraphicsUnit.Pixel );
            }
        }
Example #30
0
        protected override void Paint(
            Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates cellState,
            object value,
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // Call the base class method to paint the default cell appearance.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                null, null, errorText, cellStyle,
                advancedBorderStyle, paintParts);


            //境界線の内側に範囲を取得する
            Rectangle borderRect = this.BorderWidths(advancedBorderStyle);
            Rectangle innerRect = new Rectangle(
                cellBounds.Left + borderRect.Left,
                cellBounds.Top + borderRect.Top,
                cellBounds.Width - borderRect.Right,
                cellBounds.Height - borderRect.Bottom);

            Point middleCenter = new Point();
            middleCenter.X = innerRect.X + innerRect.Width / 2;
            middleCenter.Y = innerRect.Y + innerRect.Height / 2;

            Int32 rebirthCount = (value == null) ? 0 : (Int32)value;

            for (Int32 i = 0; i < REBIRTH_COUNT; ++i)
            {
                bool isRebirth = (i < rebirthCount);
                Image img = ResourceUtil.GetPictureRebirth(isRebirth);

                Int32 halfImgWidth = img.Width / 2;
                Int32 halfImgHeight = img.Height / 2;

                Rectangle imgRect = new Rectangle(
                    middleCenter.X + img.Width * i - halfImgWidth * REBIRTH_COUNT,
                    middleCenter.Y - halfImgHeight,
                    img.Width + 0,
                    img.Height + 0);

                graphics.DrawImage(img, imgRect);
            }
        }
Example #31
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            if (m_OwnerCell != null && m_OwnerCell.DataGridView == null)
            {
                m_OwnerCell = null; //owner cell was removed.
            }
            if (DataGridView == null ||
                (m_OwnerCell == null && m_ColumnSpan == 1 && m_RowSpan == 1))
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle,
                           paintParts);
                return;
            }

            var ownerCell   = this;
            var columnIndex = ColumnIndex;
            var columnSpan  = m_ColumnSpan;
            var rowSpan     = m_RowSpan;

            if (m_OwnerCell != null)
            {
                ownerCell      = m_OwnerCell;
                columnIndex    = m_OwnerCell.ColumnIndex;
                rowIndex       = m_OwnerCell.RowIndex;
                columnSpan     = m_OwnerCell.ColumnSpan;
                rowSpan        = m_OwnerCell.RowSpan;
                value          = m_OwnerCell.GetValue(rowIndex);
                errorText      = m_OwnerCell.GetErrorText(rowIndex);
                cellState      = m_OwnerCell.State;
                cellStyle      = m_OwnerCell.GetInheritedStyle(null, rowIndex, true);
                formattedValue = m_OwnerCell.GetFormattedValue(value,
                                                               rowIndex, ref cellStyle, null, null, DataGridViewDataErrorContexts.Display);
            }
            if (CellsRegionContainsSelectedCell(columnIndex, rowIndex, columnSpan, rowSpan))
            {
                cellState |= DataGridViewElementStates.Selected;
            }

            var cellBounds2 = DataGridViewCellExHelper.GetSpannedCellBoundsFromChildCellBounds(
                this,
                cellBounds,
                DataGridViewHelper.SingleVerticalBorderAdded(DataGridView),
                DataGridViewHelper.SingleHorizontalBorderAdded(DataGridView));

            clipBounds = DataGridViewCellExHelper.GetSpannedCellClipBounds(ownerCell, cellBounds2,
                                                                           DataGridViewHelper.SingleVerticalBorderAdded(DataGridView),
                                                                           DataGridViewHelper.SingleHorizontalBorderAdded(DataGridView));
            using (var g = DataGridView.CreateGraphics())
            {
                g.SetClip(clipBounds);
                //Paint the content.
                advancedBorderStyle = DataGridViewCellExHelper.AdjustCellBorderStyle(ownerCell);
                ownerCell.NativePaint(g, clipBounds, cellBounds2, rowIndex, cellState,
                                      value, formattedValue, errorText,
                                      cellStyle, advancedBorderStyle,
                                      paintParts & ~DataGridViewPaintParts.Border);
                //Paint the borders.
                if ((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None)
                {
                    var leftTopCell          = ownerCell;
                    var advancedBorderStyle2 = new DataGridViewAdvancedBorderStyle
                    {
                        Left   = advancedBorderStyle.Left,
                        Top    = advancedBorderStyle.Top,
                        Right  = DataGridViewAdvancedCellBorderStyle.None,
                        Bottom = DataGridViewAdvancedCellBorderStyle.None
                    };
                    leftTopCell.PaintBorder(g, clipBounds, cellBounds2, cellStyle, advancedBorderStyle2);

                    var rightBottomCell = DataGridView[columnIndex + columnSpan - 1, rowIndex + rowSpan - 1] as DataGridViewTextBoxCellEx
                                          ?? this;
                    var advancedBorderStyle3 = new DataGridViewAdvancedBorderStyle
                    {
                        Left   = DataGridViewAdvancedCellBorderStyle.None,
                        Top    = DataGridViewAdvancedCellBorderStyle.None,
                        Right  = advancedBorderStyle.Right,
                        Bottom = advancedBorderStyle.Bottom
                    };
                    rightBottomCell.PaintBorder(g, clipBounds, cellBounds2, cellStyle, advancedBorderStyle3);
                }
            }
        }
        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);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="graphics"></param>
 /// <param name="clipBounds"></param>
 /// <param name="cellBounds"></param>
 /// <param name="rowIndex"></param>
 /// <param name="elementState"></param>
 /// <param name="value"></param>
 /// <param name="formattedValue"></param>
 /// <param name="errorText"></param>
 /// <param name="cellStyle"></param>
 /// <param name="advancedBorderStyle"></param>
 /// <param name="paintParts"></param>
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     ButtonRenderer.DrawButton(graphics, cellBounds, formattedValue.ToString(), new Font("Segoe UI", 9.75f, FontStyle.Regular), focused, pushState);
 }
Example #34
0
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     graphics.DrawImage(del, cellBounds);
 }
Example #35
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                int marginForDivider = 3;
                int marginForMinutes = 20;

                Pen pen = new Pen(Calendar.ct.BorderBrush);

                // Draw the background
                graphics.FillRectangle(new SolidBrush(Calendar.ct.BackColor), cellBounds);

                // Draw the gradient if it is the current time
                DateTime now       = DateTime.Now;
                int      hour1     = rowIndex / 2;
                int      firstHalf = rowIndex % 2; // 0 means 0 to 30 minutes. 1 means 31 to 59 minutes
                if (now.Hour == hour1 && ((int)(now.Minute / 30) == firstHalf))
                {
                    LinearGradientBrush lgb = new LinearGradientBrush(cellBounds, Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                    graphics.FillRectangle(lgb, cellBounds);
                    if (firstHalf == 0)
                    {
                        graphics.DrawLine(new Pen(Calendar.ct.TodayGradientBrush), cellBounds.Left, cellBounds.Bottom, cellBounds.Right, cellBounds.Bottom);
                    }
                }

                // Draw the separator for alternate rows
                graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds.Left + marginForDivider, cellBounds.Bottom - 1, cellBounds.Right - marginForDivider, cellBounds.Bottom - 1);

                // Draw the right vertical line for the cell
                graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds.Right - 1, cellBounds.Top, cellBounds.Right - 1, cellBounds.Bottom);

                // Draw the text
                int          hour        = WeekNumber;// GetHour(rowIndex);
                RectangleF   rectHour    = RectangleF.Empty;
                RectangleF   rectMinutes = RectangleF.Empty;
                StringFormat sf          = new StringFormat();
                sf.Alignment     = StringAlignment.Far;
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;

                rectHour = new RectangleF(cellBounds.Left + 5, cellBounds.Top, cellBounds.Width - marginForMinutes, cellBounds.Height);
                graphics.DrawString(hour.ToString(), new Font("Arial", 15, FontStyle.Regular), Calendar.ct.ForeBrush, rectHour, sf);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
Example #36
0
        protected override void Paint(System.Drawing.Graphics g,
                                      System.Drawing.Rectangle clipBounds,
                                      System.Drawing.Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates cellState,
                                      object value, object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            if (Convert.ToInt16(value) == 0 || value == null)
            {
                value = 0;
            }

            int progressVal = Convert.ToInt32(value);

            float percentage     = ((float)progressVal / 100.0f);
            Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
            Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);

            // Рисование рамки ячейки
            base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

            float posX = cellBounds.X;
            float posY = cellBounds.Y;

            float textWidth  = TextRenderer.MeasureText(progressVal.ToString() + "%", cellStyle.Font).Width;
            float textHeight = TextRenderer.MeasureText(progressVal.ToString() + "%", cellStyle.Font).Height;

            // Положение текста в зависимости от выравнивания в ячейке
            switch (cellStyle.Alignment)
            {
            case DataGridViewContentAlignment.BottomCenter:
                posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
                posY = cellBounds.Y + cellBounds.Height - textHeight;
                break;

            case DataGridViewContentAlignment.BottomLeft:
                posX = cellBounds.X;
                posY = cellBounds.Y + cellBounds.Height - textHeight;
                break;

            case DataGridViewContentAlignment.BottomRight:
                posX = cellBounds.X + cellBounds.Width - textWidth;
                posY = cellBounds.Y + cellBounds.Height - textHeight;
                break;

            case DataGridViewContentAlignment.MiddleCenter:
                posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
                posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
                break;

            case DataGridViewContentAlignment.MiddleLeft:
                posX = cellBounds.X;
                posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
                break;

            case DataGridViewContentAlignment.MiddleRight:
                posX = cellBounds.X + cellBounds.Width - textWidth;
                posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
                break;

            case DataGridViewContentAlignment.TopCenter:
                posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
                posY = cellBounds.Y;
                break;

            case DataGridViewContentAlignment.TopLeft:
                posX = cellBounds.X;
                posY = cellBounds.Y;
                break;

            case DataGridViewContentAlignment.TopRight:
                posX = cellBounds.X + cellBounds.Width - textWidth;
                posY = cellBounds.Y;
                break;
            }

            if (percentage >= 0.0)
            {
                // Рисование прогресса
                g.FillRectangle(new SolidBrush(_ProgressBarColor), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width * 0.8)), cellBounds.Height / 1 - 5);
                // Рисование текста
                g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreColorBrush, posX, posY);
            }
            else
            {
                // При отрицательном значении отображается только текст
                if (this.DataGridView.CurrentRow.Index == rowIndex)
                {
                    g.DrawString(progressVal.ToString() + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), posX, posX);
                }
                else
                {
                    g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreColorBrush, posX, posY);
                }
            }
        }
Example #37
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 is not 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;

            Color backBrushColor = PaintSelectionBackground(paintParts) && cellSelected
                ? cellStyle.SelectionBackColor
                : cellStyle.BackColor;
            Color foreBrushColor = cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor;

            if (paint && 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)
            {
                return(Rectangle.Empty);
            }

            if (paint && PaintBackground(paintParts) && !backBrushColor.HasTransparency())
            {
                using var backBrush = backBrushColor.GetCachedSolidBrushScope();
                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))
            {
                switch (FlatStyle)
                {
                case FlatStyle.Standard:
                case FlatStyle.System:
                    if (DataGridView.ApplyVisualStylesToInnerCells)
                    {
                        if (paint && PaintContentBackground(paintParts))
                        {
                            PushButtonState pbState = VisualStyles.PushButtonState.Normal;
                            if ((ButtonState & (ButtonState.Pushed | ButtonState.Checked)) != 0)
                            {
                                pbState = PushButtonState.Pressed;
                            }
                            else if (DataGridView.MouseEnteredCellAddress.Y == rowIndex &&
                                     DataGridView.MouseEnteredCellAddress.X == ColumnIndex && mouseInContentBounds)
                            {
                                pbState = PushButtonState.Hot;
                            }

                            if (PaintFocus(paintParts) && cellCurrent && DataGridView.ShowFocusCues && DataGridView.Focused)
                            {
                                pbState |= PushButtonState.Default;
                            }

                            DataGridViewButtonCellRenderer.DrawButton(g, valBounds, (int)pbState);
                        }

                        resultBounds = valBounds;
                        valBounds    = DataGridViewButtonCellRenderer.DataGridViewButtonRenderer.GetBackgroundContentRectangle(g, valBounds);
                    }
                    else
                    {
                        if (paint && 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);
                    }

                    break;

                case 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, backBrushColor, isDefault: true);

                        if (!backBrushColor.HasTransparency())
                        {
                            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;
                    break;

                default:
                    Debug.Assert(FlatStyle == FlatStyle.Popup, "FlatStyle.Popup is the last flat style");
                    valBounds.Inflate(-1, -1);
                    if (paint && 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,
                                isDefault: true);
                            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,
                                isDefault: false);
                            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,
                                isDefault: false);
                            ControlPaint.DrawBorderSimple(
                                g,
                                valBounds,
                                colors.Options.HighContrast ? colors.WindowText : colors.ButtonShadow);
                        }
                    }

                    resultBounds = valBounds;
                    break;
                }
            }
            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 &&
                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 = ButtonFlatAdapter.PaintFlatLayout(
                            true,
                            SystemInformation.HighContrast,
                            1,
                            valBounds,
                            Padding.Empty,
                            false,
                            cellStyle.Font,
                            text,
                            DataGridView.Enabled,
                            DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment),
                            DataGridView.RightToLeft);
                        options.DotNetOneButtonCompat = false;
                        ButtonBaseAdapter.LayoutData layout = options.Layout();

                        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 = ButtonPopupAdapter.PaintPopupLayout(
                            paintUp,
                            SystemInformation.HighContrast ? 2 : 1,
                            valBounds,
                            Padding.Empty,
                            false,
                            cellStyle.Font,
                            text,
                            DataGridView.Enabled,
                            DataGridViewUtilities.ComputeDrawingContentAlignmentForCellStyleAlignment(cellStyle.Alignment),
                            DataGridView.RightToLeft);
                        options.DotNetOneButtonCompat = false;
                        ButtonBaseAdapter.LayoutData layout = options.Layout();

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

            if (formattedString is not null && paint && 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 = foreBrushColor;
                    }

                    TextFormatFlags flags = DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(
                        DataGridView.RightToLeftInternal,
                        cellStyle.Alignment,
                        cellStyle.WrapMode);

                    TextRenderer.DrawText(
                        g,
                        formattedString,
                        cellStyle.Font,
                        valBounds,
                        textColor,
                        flags);
                }
            }

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

            return(resultBounds);
        }
Example #38
0
        protected override void Paint(
            Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates elementState,
            object value,
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // The button cell is disabled, so paint the border, background, and disabled button for the cell.
            if (!enabledValue)
            {
                var currentContext = BufferedGraphicsManager.Current;

                using (var myBuffer = currentContext.Allocate(graphics, cellBounds))
                {
                    // Draw the cell background, if specified.
                    if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
                    {
                        using (var cellBackground = new SolidBrush(cellStyle.BackColor))
                        {
                            myBuffer.Graphics.FillRectangle(cellBackground, cellBounds);
                        }
                    }

                    // Draw the cell borders, if specified.
                    if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
                    {
                        PaintBorder(myBuffer.Graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
                    }

                    // Calculate the area in which to draw the button.
                    var buttonArea       = cellBounds;
                    var buttonAdjustment = BorderWidths(advancedBorderStyle);
                    buttonArea.X      += buttonAdjustment.X;
                    buttonArea.Y      += buttonAdjustment.Y;
                    buttonArea.Height -= buttonAdjustment.Height;
                    buttonArea.Width  -= buttonAdjustment.Width;

                    // Draw the disabled button.
                    ButtonRenderer.DrawButton(myBuffer.Graphics, buttonArea, PushButtonState.Disabled);

                    // Draw the disabled button text.
                    var formattedValueString = FormattedValue as string;
                    if (formattedValueString != null)
                    {
                        TextRenderer.DrawText(myBuffer.Graphics, formattedValueString, DataGridView.Font, buttonArea, SystemColors.GrayText, TextFormatFlags.PreserveGraphicsTranslateTransform | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
                    }

                    myBuffer.Render();
                }
            }
            else
            {
                // The button cell is enabled, so let the base class handle the painting.
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
        }
                protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
                {
                    Image icon = value as Image;

                    if (icon == null)
                    {
                        return;
                    }

                    PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)DataGridView.Rows[RowIndex];

                    if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled)
                    {
                        graphics.FillRectangle(
                            new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor), cellBounds.X,
                            cellBounds.Y, cellBounds.Width, cellBounds.Height);
                    }
                    else
                    {
                        graphics.FillRectangle(new SolidBrush(DataGridView.DefaultCellStyle.BackColor), cellBounds.X,
                                               cellBounds.Y, cellBounds.Width, cellBounds.Height);
                    }

                    if (row.Enabled)
                    {
                        graphics.DrawImage(icon, cellBounds.X, cellBounds.Y + 3, icon.Width, icon.Height);
                    }
                    else
                    {
                        graphics.DrawImage(icon, new Rectangle(cellBounds.X, cellBounds.Y + 3, icon.Width, icon.Height),
                                           0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel,
                                           Drawing.GreyScaleAttributes);
                    }
                }
                protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
                {
                    Pool pool = value as Pool;

                    if (pool != null)
                    {
                        base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
                    }
                    else
                    {
                        Host host = value as Host;
                        if (host != null)
                        {
                            PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)this.DataGridView.Rows[this.RowIndex];
                            if (row.HasPool)
                            {
                                Image hostIcon = Images.GetImage16For(host);
                                base.Paint(graphics, clipBounds,
                                           new Rectangle(cellBounds.X + 16, cellBounds.Y, cellBounds.Width - 16,
                                                         cellBounds.Height), rowIndex, cellState, value, formattedValue,
                                           errorText, cellStyle, advancedBorderStyle, paintParts);

                                if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled)
                                {
                                    graphics.FillRectangle(
                                        new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor), cellBounds.X,
                                        cellBounds.Y, hostIcon.Width, cellBounds.Height);
                                }
                                else
                                {
                                    graphics.FillRectangle(new SolidBrush(DataGridView.DefaultCellStyle.BackColor),
                                                           cellBounds.X, cellBounds.Y, hostIcon.Width, cellBounds.Height);
                                }

                                if (row.Enabled)
                                {
                                    graphics.DrawImage(hostIcon, cellBounds.X, cellBounds.Y + 3, hostIcon.Width,
                                                       hostIcon.Height);
                                }
                                else
                                {
                                    graphics.DrawImage(hostIcon,
                                                       new Rectangle(cellBounds.X, cellBounds.Y + 3,
                                                                     hostIcon.Width, hostIcon.Height),
                                                       0, 0, hostIcon.Width, hostIcon.Height, GraphicsUnit.Pixel,
                                                       Drawing.GreyScaleAttributes);
                                }
                            }
                            else
                            {
                                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue,
                                           errorText, cellStyle, advancedBorderStyle, paintParts);
                            }
                        }
                    }
                }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            TreeGridNode node = this.OwningNode;

            if (node == null)
            {
                return;
            }

            Image image = node.Image;

            if (this._imageHeight == 0 && image != null)
            {
                this.UpdateStyle();
            }

            // paint the cell normally
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            // TODO: Indent width needs to take image size into account
            Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, INDENT_WIDTH, cellBounds.Height - 1);
            int       glyphHalf = glyphRect.Width / 2;

            //TODO: This painting code needs to be rehashed to be cleaner
            int level = this.Level;

            //TODO: Rehash this to take different Imagelayouts into account. This will speed up drawing
            //		for images of the same size (ImageLayout.None)
            if (image != null)
            {
                Point pp;
                if (_imageHeight > cellBounds.Height)
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, cellBounds.Y + _imageHeightOffset);
                }
                else
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, (cellBounds.Height / 2 - _imageHeight / 2) + cellBounds.Y);
                }

                // Graphics container to push/pop changes. This enables us to set clipping when painting
                // the cell's image -- keeps it from bleeding outsize of cells.
                System.Drawing.Drawing2D.GraphicsContainer gc = graphics.BeginContainer();
                {
                    graphics.SetClip(cellBounds);
                    graphics.DrawImageUnscaled(image, pp);
                }
                graphics.EndContainer(gc);
            }

            // Paint tree lines
            if (node._grid.ShowLines)
            {
                using (Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f))
                {
                    linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                    bool isLastSibling  = node.IsLastSibling;
                    bool isFirstSibling = node.IsFirstSibling;
                    if (node.Level == 1)
                    {
                        // the Root nodes display their lines differently
                        if (isFirstSibling && isLastSibling)
                        {
                            // only node, both first and last. Just draw horizontal line
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isFirstSibling)
                        {
                            // first sibling doesn't draw the line extended above. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.X + 4, cellBounds.Bottom);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }
                    }
                    else
                    {
                        if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }

                        // paint lines of previous levels to the root
                        TreeGridNode previousNode   = node.Parent;
                        int          horizontalStop = (glyphRect.X + 4) - INDENT_WIDTH;

                        while (!previousNode.IsRoot)
                        {
                            if (previousNode.HasChildren && !previousNode.IsLastSibling)
                            {
                                // paint vertical line
                                graphics.DrawLine(linePen, horizontalStop, cellBounds.Top, horizontalStop, cellBounds.Bottom);
                            }
                            previousNode   = previousNode.Parent;
                            horizontalStop = horizontalStop - INDENT_WIDTH;
                        }
                    }
                }
            }

            if (node.HasChildren || node._grid.VirtualNodes)
            {
                try
                {
                    // Paint node glyphs
                    if (node.IsExpanded)
                    {
                        node._grid.rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                    }
                    else
                    {
                        node._grid.rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                    }
                }
                catch
                { }
            }
        }
        /// <summary>
        /// This member overrides DataGridViewCell.Paint.
        /// </summary>
        /// <param name="graphics">The Graphics used to paint the DataGridViewCell.</param>
        /// <param name="clipBounds">A Rectangle that represents the area of the DataGridView that needs to be repainted.</param>
        /// <param name="cellBounds">A Rectangle that contains the bounds of the DataGridViewCell that is being painted.</param>
        /// <param name="rowIndex">The row index of the cell that is being painted.</param>
        /// <param name="cellState">A bitwise combination of DataGridViewElementStates values that specifies the state of the cell.</param>
        /// <param name="value">The data of the DataGridViewCell that is being painted.</param>
        /// <param name="formattedValue">The formatted data of the DataGridViewCell that is being painted.</param>
        /// <param name="errorText">An error message that is associated with the cell.</param>
        /// <param name="cellStyle">A DataGridViewCellStyle that contains formatting and style information about the cell.</param>
        /// <param name="advancedBorderStyle">A DataGridViewAdvancedBorderStyle that contains border styles for the cell that is being painted.</param>
        /// <param name="paintParts">A bitwise combination of the DataGridViewPaintParts values that specifies which parts of the cell need to be painted.</param>
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds,
                                      Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates cellState,
                                      object value,
                                      object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            if (DataGridView is KryptonDataGridView kDgv)
            {
                // Should we draw the content foreground?
                if ((paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground)
                {
                    CheckState checkState = CheckState.Unchecked;

                    if (formattedValue is CheckState state)
                    {
                        checkState = state;
                    }
                    else if (formattedValue is bool)
                    {
                        if ((bool)formattedValue)
                        {
                            checkState = CheckState.Checked;
                        }
                        else
                        {
                            checkState = CheckState.Unchecked;
                        }
                    }

                    // Is this cell the currently active cell
                    bool currentCell = (rowIndex == DataGridView.CurrentCellAddress.Y) &&
                                       (ColumnIndex == DataGridView.CurrentCellAddress.X);

                    // Is this cell the same as the one with the mouse inside it
                    Point mouseEnteredCellAddress = MouseEnteredCellAddressInternal;
                    bool  mouseCell = (rowIndex == mouseEnteredCellAddress.Y) &&
                                      (ColumnIndex == mouseEnteredCellAddress.X);

                    // Snoop tracking and pressed status from the base class implementation
                    bool tracking = mouseCell && MouseInContentBoundsInternal;
                    bool pressed  = currentCell && ((ButtonStateInternal & ButtonState.Pushed) == ButtonState.Pushed);

                    using (RenderContext renderContext = new RenderContext(kDgv, graphics, cellBounds, kDgv.Renderer))
                    {
                        Size checkBoxSize;

                        // Find out the requested size of the check box drawing
                        using (ViewLayoutContext viewContent = new ViewLayoutContext(kDgv, kDgv.Renderer))
                        {
                            checkBoxSize = renderContext.Renderer.RenderGlyph.GetCheckBoxPreferredSize(viewContent,
                                                                                                       kDgv.Redirector,
                                                                                                       kDgv.Enabled && !base.ReadOnly,
                                                                                                       checkState,
                                                                                                       tracking,
                                                                                                       pressed);
                        }
                        // Remember the original cell bounds
                        Rectangle startBounds = cellBounds;

                        // Prevent check box overlapping the bottom/right border
                        cellBounds.Width--;
                        cellBounds.Height--;

                        // Adjust the horizontal alignment
                        switch (cellStyle.Alignment)
                        {
                        case DataGridViewContentAlignment.NotSet:
                        case DataGridViewContentAlignment.TopCenter:
                        case DataGridViewContentAlignment.MiddleCenter:
                        case DataGridViewContentAlignment.BottomCenter:
                            cellBounds.X += (cellBounds.Width - checkBoxSize.Width) / 2;
                            break;

                        case DataGridViewContentAlignment.TopRight:
                        case DataGridViewContentAlignment.MiddleRight:
                        case DataGridViewContentAlignment.BottomRight:
                            cellBounds.X = cellBounds.Right - checkBoxSize.Width;
                            break;
                        }

                        // Adjust the vertical alignment
                        switch (cellStyle.Alignment)
                        {
                        case DataGridViewContentAlignment.NotSet:
                        case DataGridViewContentAlignment.MiddleLeft:
                        case DataGridViewContentAlignment.MiddleCenter:
                        case DataGridViewContentAlignment.MiddleRight:
                            cellBounds.Y += (cellBounds.Height - checkBoxSize.Height) / 2;
                            break;

                        case DataGridViewContentAlignment.BottomLeft:
                        case DataGridViewContentAlignment.BottomCenter:
                        case DataGridViewContentAlignment.BottomRight:
                            cellBounds.Y = cellBounds.Bottom - checkBoxSize.Height;
                            break;
                        }

                        // Make the cell the same size as the check box itself
                        cellBounds.Width  = checkBoxSize.Width;
                        cellBounds.Height = checkBoxSize.Height;

                        // Remember the current drawing bounds
                        _contentBounds = new Rectangle(cellBounds.X - startBounds.X,
                                                       cellBounds.Y - startBounds.Y,
                                                       cellBounds.Width, cellBounds.Height);

                        // Perform actual drawing of the check box
                        renderContext.Renderer.RenderGlyph.DrawCheckBox(renderContext,
                                                                        cellBounds,
                                                                        kDgv.Redirector,
                                                                        kDgv.Enabled && !base.ReadOnly,
                                                                        checkState,
                                                                        tracking,
                                                                        pressed);
                    }
                }
            }
            else
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                           cellState, value, formattedValue, errorText,
                           cellStyle, advancedBorderStyle, paintParts);
            }
        }
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds,
                                      Rectangle cellBounds,
                                      int rowIndex,
                                      DataGridViewElementStates cellState,
                                      object value,
                                      object formattedValue,
                                      string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle, advancedBorderStyle, paintParts);

            List <KeyValuePair <String, String> > kvps = value as List <KeyValuePair <String, String> >;

            if (kvps == null)
            {
                return;
            }

            // Paint the background
            using (var brush = new SolidBrush(Selected ? cellStyle.SelectionBackColor : cellStyle.BackColor))
                graphics.FillRectangle(brush, cellBounds.X + cellStyle.Padding.Left,
                                       cellBounds.Y + cellStyle.Padding.Top, cellBounds.Width - cellStyle.Padding.Horizontal,
                                       cellBounds.Height - cellStyle.Padding.Vertical);

            // Go through drawing the keys, making note of their widths so we know how much to indent the values by
            // and keeping track of the Y positions so we can place the value labels without measuring.
            int indent   = 0;
            int currentY = 0;

            int[] heights = new int[kvps.Count];
            for (int i = 0; i < kvps.Count; i++)
            {
                KeyValuePair <String, String> kvp = kvps[i];
                if (kvp.Key == String.Empty && kvp.Value == String.Empty)
                {
                    // empty key and value means we want a vertical gap
                    currentY  += KVP_VERTICAL_SPACE_DIVIDER + KVP_SPACE;
                    heights[i] = KVP_VERTICAL_SPACE_DIVIDER;
                    continue;
                }
                Size s = Drawing.MeasureText(kvp.Key, cellStyle.Font);
                if (s.Width > indent)
                {
                    indent = s.Width;
                }

                using (var brush = new SolidBrush(Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor))
                    graphics.DrawString(
                        kvp.Key,
                        cellStyle.Font, brush,
                        (float)(cellBounds.X + cellStyle.Padding.Left),
                        (float)(cellBounds.Y + currentY));

                currentY  += s.Height + KVP_SPACE;
                heights[i] = s.Height;
            }
            currentY = 0;
            // Add in the space between the key and value text
            indent += KVP_SPACE;
            // Now print the values
            for (int i = 0; i < kvps.Count; i++)
            {
                KeyValuePair <String, String> kvp = kvps[i];

                using (var brush = new SolidBrush(Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor))
                    graphics.DrawString(kvp.Value, cellStyle.Font, brush,
                                        (float)(cellBounds.X + cellStyle.Padding.Left + indent),
                                        (float)(cellBounds.Y + currentY));

                currentY += heights[i] + KVP_SPACE;
            }
        }
Example #44
0
        protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            ReadOnly = true;

            // Draw the cell border
            base.Paint(g, clipBounds, cellBounds,
                       rowIndex, cellState, value, formattedValue, errorText,
                       cellStyle, advancedBorderStyle, DataGridViewPaintParts.Border);

            try
            {
                // Draw the ProgressBar to an in-memory bitmap
                Bitmap    bmp       = new Bitmap(cellBounds.Width, cellBounds.Height);
                Rectangle bmpBounds = new Rectangle(0, 0, cellBounds.Width, cellBounds.Height);
                _progressBar.Size = cellBounds.Size;
                _progressBar.DrawToBitmap(bmp, bmpBounds);

                // Draw the bitmap on the cell
                g.DrawImage(bmp, cellBounds);

                if (string.IsNullOrEmpty(_message))
                {
                    return;
                }

                // Replace special value placeholders
                var editedMessage = _message.Replace(MessageSpecialValue.CurrentValue, Value.ToString())
                                    .Replace(MessageSpecialValue.Maximum, Maximum.ToString())
                                    .Replace(MessageSpecialValue.Minimum, Minimum.ToString())
                                    .Replace(MessageSpecialValue.Percentage, Math.Floor(((int)Value / (double)Maximum) * 100.0) + "%");

                // Write text over bar)
                base.Paint(g, clipBounds, cellBounds,
                           rowIndex, cellState, value, editedMessage, errorText,
                           cellStyle, advancedBorderStyle, DataGridViewPaintParts.ContentForeground);
            }
            catch (ArgumentOutOfRangeException)
            {
                // Row probably couldn't be accessed
            }
        }
Example #45
0
        protected Rectangle PaintPrivate(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            //System.Diagnostics.Debug.WriteLine(string.Format("Painting Cell row {0} for rowindex {2} with rectangle {1}", this.RowIndex, cellBounds, rowIndex));
            SolidBrush cachedBrush;
            Rectangle  empty = Rectangle.Empty;

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

            borderedCellRectangle.Offset(rectangle2.X, rectangle2.Y);
            borderedCellRectangle.Width  -= rectangle2.Right;
            borderedCellRectangle.Height -= rectangle2.Bottom;
            Point currentCellAddress           = base.DataGridView.CurrentCellAddress;
            bool  isFirstCell                  = (currentCellAddress.X == base.ColumnIndex) && (currentCellAddress.Y == rowIndex);
            bool  flagisFirstCellAndNotEditing = isFirstCell && (base.DataGridView.EditingControl != null);
            bool  thisCellIsSelected           = (cellState & DataGridViewElementStates.Selected) != DataGridViewElementStates.None;

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

            if ((text != null) && (!flagisFirstCellAndNotEditing))
            {
                int y = (cellStyle.WrapMode == DataGridViewTriState.True) ? 1 : 2;
                borderedCellRectangle.Offset(0, y);
                borderedCellRectangle.Width   = borderedCellRectangle.Width;
                borderedCellRectangle.Height -= y + 1;
                if ((borderedCellRectangle.Width > 0) && (borderedCellRectangle.Height > 0))
                {
                    TextFormatFlags flags = //DataGridViewUtilities.ComputeTextFormatFlagsForCellStyleAlignment(base.DataGridView.RightToLeftInternal, cellStyle.Alignment, cellStyle.WrapMode);
                                            TextFormatFlags.PathEllipsis;

                    if (PaintContentForeground(paintParts))
                    {
                        if ((flags & TextFormatFlags.SingleLine) != TextFormatFlags.GlyphOverhangPadding)
                        {
                            flags |= TextFormatFlags.EndEllipsis;
                        }
                        DataGridViewFilePathColumn filePathColumn = (DataGridViewFilePathColumn)this.DataGridView.Columns[ColumnIndex];
                        if (true && filePathColumn.ShowBrowseButton)
                        {
                            if (this.RowIndex >= 0)
                            {
                                Button browseButton = GetBrowseButton(filePathColumn.UseOpenFileDialogOnButtonClick);
                                bool   changed      = false;
                                if ((browseButton.Width != Math.Max(10, borderedCellRectangle.Width / 4)) && (browseButton.Width != 20))
                                {
                                    System.Diagnostics.Trace.WriteLine(string.Format("browseButton Width was incorrect:{0} for given rectangle:{1}", browseButton.Width, borderedCellRectangle));
                                    browseButton.Width = Math.Max(10, borderedCellRectangle.Width / 4);
                                    browseButton.Width = Math.Min(browseButton.Width, 20);
                                    changed            = true;
                                }
                                if (browseButton.Height != (borderedCellRectangle.Height - 2))
                                {
                                    System.Diagnostics.Trace.WriteLine(string.Format("browseButton Height was incorrect:{0} for given rectangle:{1}", browseButton.Height, borderedCellRectangle));
                                    browseButton.Height = borderedCellRectangle.Height + 2;
                                    changed             = true;
                                }
                                Point loc = new Point();
                                loc.X = borderedCellRectangle.X + borderedCellRectangle.Width - browseButton.Width;
                                loc.Y = borderedCellRectangle.Y - 2;
                                if (browseButton.Location != loc)
                                {
                                    System.Diagnostics.Trace.WriteLine(string.Format("browseButton location was incorrect:{0} for given rectangle:{1} with loc: {2}", browseButton.Location, borderedCellRectangle, loc));
                                    browseButton.Location = loc;
                                    changed = true;
                                }
                                if (changed)
                                {
                                    browseButton.Invalidate();
                                }
                                if (!this.DataGridView.Controls.Contains(browseButton))
                                {
                                    this.DataGridView.Controls.Add(browseButton);
                                }
                                borderedCellRectangle.Width -= browseButton.Width;
                            }
                        }
                        TextRenderer.DrawText(graphics, text, cellStyle.Font, borderedCellRectangle, thisCellIsSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor, flags);
                    }
                }
            }
            if ((base.DataGridView.ShowCellErrors) && PaintErrorIcon(paintParts))
            {
                PaintErrorIcon(graphics, cellStyle, rowIndex, cellBounds, cellValueBounds, errorText);
            }
            return(empty);
        }
Example #46
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);
        }
Example #47
0
            protected override void Paint(Graphics graphics,
                                          Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                          DataGridViewElementStates elementState, object value,
                                          object formattedValue, string errorText,
                                          DataGridViewCellStyle cellStyle,
                                          DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                          DataGridViewPaintParts paintParts)
            {
                // The button cell is disabled, so paint the border,
                // background, and disabled button for the cell.
                if (!this.enabledValue)
                {
                    // Draw the cell background, if specified.
                    if ((paintParts & DataGridViewPaintParts.Background) ==
                        DataGridViewPaintParts.Background)
                    {
                        SolidBrush cellBackground =
                            new SolidBrush(cellStyle.BackColor);
                        graphics.FillRectangle(cellBackground, cellBounds);
                        cellBackground.Dispose();
                    }

                    // Draw the cell borders, if specified.
                    if ((paintParts & DataGridViewPaintParts.Border) ==
                        DataGridViewPaintParts.Border)
                    {
                        PaintBorder(graphics, clipBounds, cellBounds, cellStyle,
                                    advancedBorderStyle);
                    }

                    // Calculate the area in which to draw the button.
                    Rectangle buttonArea       = cellBounds;
                    Rectangle buttonAdjustment =
                        this.BorderWidths(advancedBorderStyle);
                    buttonArea.X      += buttonAdjustment.X;
                    buttonArea.Y      += buttonAdjustment.Y;
                    buttonArea.Height -= buttonAdjustment.Height;
                    buttonArea.Width  -= buttonAdjustment.Width;

                    // Draw the disabled button.
                    ButtonRenderer.DrawButton(graphics, buttonArea,
                                              PushButtonState.Disabled);


                    // Draw the disabled button text.
                    if (this.FormattedValue is String)
                    {
                        TextRenderer.DrawText(graphics,
                                              (string)this.FormattedValue,
                                              this.DataGridView.Font,
                                              buttonArea, SystemColors.GrayText);
                    }
                }
                else
                {
                    // The button cell is enabled, so let the base class
                    // handle the painting.
                    base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                               elementState, value, formattedValue, errorText,
                               cellStyle, advancedBorderStyle, paintParts);
                }
            }
Example #48
0
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     if (cellStyle == null)
     {
         throw new ArgumentNullException("cellStyle");
     }
     this.PaintPrivate(graphics, clipBounds, cellBounds, rowIndex, cellState, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts, false, false, true);
 }
 //override button appearance
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
                               int rowIndex, DataGridViewElementStates elementState, object value,
                               object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
                               DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     if (!_enabledValue)
     {
         if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
         {
             DrawCellBackground(ref graphics, cellStyle.BackColor, cellBounds);
         }
         if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border)
         {
             PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
         }
         Rectangle buttonArea = cellBounds;
         SetButtonArea(ref buttonArea, ref advancedBorderStyle);
         ButtonRenderer.DrawButton(graphics, buttonArea, PushButtonState.Disabled);
         if (FormattedValue is String)
         {
             TextRenderer.DrawText(graphics, (string)FormattedValue, DataGridView.Font, buttonArea, SystemColors.GrayText);
         }
     }
     else
     {
         base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     }
 }
Example #50
0
        protected override void Paint(
            Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
            int rowIndex, DataGridViewElementStates cellState,
            object value, object formattedValue, string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            if (this.CellBehavior == ADGVColumnHeaderCellBehavior.SortingStandartGlyph)
            {
                switch (this.ActiveSortType)
                {
                case ADGVSortType.ASC:
                    this.SortGlyphDirection = SortOrder.Ascending;
                    break;

                case ADGVSortType.DESC:
                    this.SortGlyphDirection = SortOrder.Descending;
                    break;

                case ADGVSortType.None:
                    this.SortGlyphDirection = SortOrder.None;
                    break;
                }
            }
            else
            {
                this.SortGlyphDirection = SortOrder.None;
            }

            base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                       cellState, value, formattedValue,
                       errorText, cellStyle, advancedBorderStyle, paintParts);

            if (this.CellBehavior != ADGVColumnHeaderCellBehavior.SortingStandartGlyph && this.CellBehavior != ADGVColumnHeaderCellBehavior.DisabledHidden && paintParts.HasFlag(DataGridViewPaintParts.ContentBackground))
            {
                Image filterImage = Properties.Resources.AddFilter;

                if (this.cellBehavior == ADGVColumnHeaderCellBehavior.Sorting || this.ActiveFilterType == ADGVFilterType.None)
                {
                    switch (this.ActiveSortType)
                    {
                    case ADGVSortType.ASC:
                        filterImage = Properties.Resources.ASC;
                        break;

                    case ADGVSortType.DESC:
                        filterImage = Properties.Resources.DESC;
                        break;

                    case ADGVSortType.None:
                        filterImage = Properties.Resources.AddFilter;
                        break;
                    }
                }
                else
                {
                    switch (this.ActiveSortType)
                    {
                    case ADGVSortType.ASC:
                        filterImage = Properties.Resources.FilterASC;
                        break;

                    case ADGVSortType.DESC:
                        filterImage = Properties.Resources.FilterDESC;
                        break;

                    case ADGVSortType.None:
                        filterImage = Properties.Resources.Filter;
                        break;
                    }
                }

                this.filterButtonOffsetBounds = this.GetFilterButtonBounds(true);
                this.filterButtonImageBounds  = this.GetFilterButtonBounds(false);
                Rectangle buttonBounds = this.filterButtonOffsetBounds;
                if (buttonBounds != null && clipBounds.IntersectsWith(buttonBounds))
                {
                    ControlPaint.DrawBorder(graphics, buttonBounds, Color.Gray, ButtonBorderStyle.Solid);
                    buttonBounds.Inflate(-1, -1);
                    using (Brush b = new SolidBrush((this.CellBehavior != ADGVColumnHeaderCellBehavior.Disabled && this.filterButtonOver) ? Color.LightGray : Color.White))
                        graphics.FillRectangle(b, buttonBounds);

                    graphics.DrawImage(filterImage, buttonBounds);
                }
            }
        }
        /// <summary>
        /// Paints the column header cell, including the drop-down button.
        /// </summary>
        /// <param name="graphics">The Graphics used to paint the DataGridViewCell.</param>
        /// <param name="clipBounds">A Rectangle that represents the area of the DataGridView that needs to be repainted.</param>
        /// <param name="cellBounds">A Rectangle that contains the bounds of the DataGridViewCell that is being painted.</param>
        /// <param name="rowIndex">The row index of the cell that is being painted.</param>
        /// <param name="cellState">A bitwise combination of DataGridViewElementStates values that specifies the state of the cell.</param>
        /// <param name="value">The data of the DataGridViewCell that is being painted.</param>
        /// <param name="formattedValue">The formatted data of the DataGridViewCell that is being painted.</param>
        /// <param name="errorText">An error message that is associated with the cell.</param>
        /// <param name="cellStyle">A DataGridViewCellStyle that contains formatting and style information about the cell.</param>
        /// <param name="advancedBorderStyle">A DataGridViewAdvancedBorderStyle that contains border styles for the cell that is being painted.</param>
        /// <param name="paintParts">A bitwise combination of the DataGridViewPaintParts values that specifies which parts of the cell need to be painted.</param>
        protected override void Paint(
            Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
            int rowIndex, DataGridViewElementStates cellState,
            object value, object formattedValue, string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // Use the base method to paint the default appearance.
            base.Paint(graphics, clipBounds, cellBounds, rowIndex,
                       cellState, value, formattedValue,
                       errorText, cellStyle, advancedBorderStyle, paintParts);

            // Continue only if filtering is enabled and ContentBackground is
            // part of the paint request.
            if ((paintParts & DataGridViewPaintParts.ContentBackground) == 0)
            {
                return;
            }

            // Retrieve the current button bounds.
            Rectangle buttonBounds = DropDownButtonBounds;

            // Continue only if the buttonBounds is big enough to draw.
            if (buttonBounds.Width < 1 || buttonBounds.Height < 1)
            {
                return;
            }

            // Paint the button manually or using visual styles if visual styles
            // are enabled, using the correct state depending on whether the
            // filter list is showing and whether there is a filter in effect
            // for the current column.
            if (Application.RenderWithVisualStyles)
            {
                ComboBoxState state = ComboBoxState.Normal;

                if (dropDownListBoxShowing)
                {
                    state = ComboBoxState.Pressed;
                }
                ComboBoxRenderer.DrawDropDownButton(
                    graphics, buttonBounds, state);
            }
            else
            {
                // Determine the pressed state in order to paint the button
                // correctly and to offset the down arrow.
                Int32           pressedOffset = 0;
                PushButtonState state         = PushButtonState.Normal;
                if (dropDownListBoxShowing)
                {
                    state         = PushButtonState.Pressed;
                    pressedOffset = 1;
                }
                ButtonRenderer.DrawButton(graphics, buttonBounds, state);

                graphics.FillPolygon(SystemBrushes.ControlText, new Point[] {
                    new Point(
                        buttonBounds.Width / 2 +
                        buttonBounds.Left - 1 + pressedOffset,
                        buttonBounds.Height * 3 / 4 +
                        buttonBounds.Top - 1 + pressedOffset),
                    new Point(
                        buttonBounds.Width / 4 +
                        buttonBounds.Left + pressedOffset,
                        buttonBounds.Height / 2 +
                        buttonBounds.Top - 1 + pressedOffset),
                    new Point(
                        buttonBounds.Width * 3 / 4 +
                        buttonBounds.Left - 1 + pressedOffset,
                        buttonBounds.Height / 2 +
                        buttonBounds.Top - 1 + pressedOffset)
                });
            }
        }
Example #52
0
 protected static bool PaintSelectionBackground(DataGridViewPaintParts paintParts)
 {
     return((paintParts & DataGridViewPaintParts.SelectionBackground) != DataGridViewPaintParts.None);
 }
Example #53
0
 protected static bool PaintContentForeground(DataGridViewPaintParts paintParts)
 {
     return((paintParts & DataGridViewPaintParts.ContentForeground) != DataGridViewPaintParts.None);
 }
Example #54
0
 protected static bool PaintBorder(DataGridViewPaintParts paintParts)
 {
     return((paintParts & DataGridViewPaintParts.Border) != DataGridViewPaintParts.None);
 }
        protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            DataGridViewImageButtomColumn col = this.OwningColumn as DataGridViewImageButtomColumn;

            if (col == null)
            {
                return;
            }
            Image img = col.BackgroundImage;

            if (img == null)
            {
                return;
            }
            graphics.DrawImage(img, cellBounds.X + ((cellBounds.Width - img.Size.Width) / 2), cellBounds.Y + ((cellBounds.Height - img.Size.Height) / 2));

            //graphics.FillRectangle(Brushes.Black, cellBounds);
        }
Example #56
0
 protected static bool PaintFocus(DataGridViewPaintParts paintParts)
 {
     return((paintParts & DataGridViewPaintParts.Focus) != DataGridViewPaintParts.None);
 }
Example #57
0
 private void NativePaint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
 }
Example #58
0
 protected static bool PaintErrorIcon(DataGridViewPaintParts paintParts)
 {
     return((paintParts & DataGridViewPaintParts.ErrorIcon) != DataGridViewPaintParts.None);
 }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                object o;
                o = value;

                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, "", "", errorText, cellStyle, advancedBorderStyle,
                           paintParts);

                //load Icons from resources
                //arrows
                ImageList GridIcons = new ImageList();
                GridIcons.ColorDepth = ColorDepth.Depth32Bit;

                string iconOkName;
                string iconFailName;
                string iconNoneName;
                //Icon icon;
                //Bitmap icon;

                //Ok
                iconOkName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Up.png";

                //Fail
                iconFailName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Down.png";

                //None
                iconNoneName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.Question.png";


                int ngXlocation = (cellBounds.Width - 16);
                int ngYlocation = (cellBounds.Height - 16);
                if (ngXlocation < 0)
                {
                    ngXlocation = 0;
                }
                if (ngYlocation < 0)
                {
                    ngYlocation = 0;
                }
                ngXlocation = ngXlocation / 2;
                ngYlocation = ngYlocation / 2;

                Rectangle ng = new Rectangle(cellBounds.X + ngXlocation, cellBounds.Y + ngYlocation, 16, 16);

                if ((((o) != null)))
                {
                    Single c;
                    c = Conversions.ToSingle(o);
                    //Debug
                    //MessageBox.Show(c)

                    Brush backBrush = new SolidBrush(cellStyle.BackColor);

                    if (elementState == DataGridViewElementStates.Selected)
                    {
                        backBrush = new SolidBrush(Color.Gold);
                    }

                    //erase background
                    if (c == 1)
                    {
                        //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height)
                        using (Bitmap tmpBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(iconOkName)))
                        {
                            tmpBitmap.MakeTransparent();
                            graphics.DrawImage(tmpBitmap, ng);
                        }
                    }
                    else if (c == 0)
                    {
                        //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height)
                        using (Bitmap tmpBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(iconFailName)))
                        {
                            tmpBitmap.MakeTransparent();
                            graphics.DrawImage(tmpBitmap, ng);
                        }
                    }
                    else
                    {
                        //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height)
                        using (Bitmap tmpBitmap = new Bitmap(this.GetType().Assembly.GetManifestResourceStream(iconNoneName)))
                        {
                            tmpBitmap.MakeTransparent();
                            graphics.DrawImage(tmpBitmap, ng);
                        }
                    }
                }

                PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
            catch
            {
                // empty catch
                //MessageBox.Show(ex.Message)
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle,
                           paintParts);
                PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);
            }
        }
Example #60
0
 protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
 {
     using (var normalBrush = new SolidBrush(OwningRow.DefaultCellStyle.BackColor))
         using (var selectedBrush = new SolidBrush(OwningRow.DefaultCellStyle.SelectionBackColor))
         {
             graphics.FillRectangle(
                 (elementState & DataGridViewElementStates.Selected) != 0 ? selectedBrush : normalBrush,
                 cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height);
         }
 }