Beispiel #1
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 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);
              }
        }
        /// <summary>
        /// Custom paints the cell. The base implementation of the DataGridViewTextBoxCell type is called first,
        /// dropping the icon error and content foreground parts. Those two parts are painted by this custom implementation.
        /// In this sample, the non-edited NumericUpDown control is painted by using a call to Control.DrawToBitmap. This is
        /// an easy solution for painting controls but it's not necessarily the most performant. An alternative would be to paint
        /// the NumericUpDown control piece by piece (text and up/down buttons).
        /// </summary>
        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;
            }
            //if (paintingNumericUpDown.IsDisposed)
            //{
            //    paintingNumericUpDown =new NumericUpDown();
            //}
            // 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));

            Point ptCurrentCell = this.DataGridView.CurrentCellAddress;
            bool cellCurrent = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex;
            bool cellEdited = cellCurrent && this.DataGridView.EditingControl != null;

            // If the cell is in editing mode, there is nothing else to paint
            if (!cellEdited)
            {
                if (PartPainted(paintParts, DataGridViewPaintParts.ContentForeground))
                {
                    // Paint a NumericUpDown control
                    // Take the borders into account
                    Rectangle borderWidths = BorderWidths(advancedBorderStyle);
                    Rectangle valBounds = cellBounds;
                    valBounds.Offset(borderWidths.X, borderWidths.Y);
                    valBounds.Width -= borderWidths.Right;
                    valBounds.Height -= borderWidths.Bottom;
                    // Also take the padding into account
                    if (cellStyle.Padding != Padding.Empty)
                    {
                        if (this.DataGridView.RightToLeft == RightToLeft.Yes)
                        {
                            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;
                    }
                    // Determine the NumericUpDown control location
                    valBounds = GetAdjustedEditingControlBounds(valBounds, cellStyle);

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

                    if (renderingBitmap.Width < valBounds.Width ||
                        renderingBitmap.Height < valBounds.Height)
                    {
                        // The static bitmap is too small, a bigger one needs to be allocated.
                        renderingBitmap.Dispose();
                        renderingBitmap = new Bitmap(valBounds.Width, valBounds.Height);
                    }
                    // Make sure the NumericUpDown control is parented to a visible control
                    if (paintingNumericUpDown.Parent == null || !paintingNumericUpDown.Parent.Visible)
                    {
                        paintingNumericUpDown.Parent = this.DataGridView;
                    }
                    // Set all the relevant properties
                    paintingNumericUpDown.TextAlign = DataGridViewNumericUpDownCell.TranslateAlignment(cellStyle.Alignment);
                    paintingNumericUpDown.DecimalPlaces = this.DecimalPlaces;
                    paintingNumericUpDown.ThousandsSeparator = this.ThousandsSeparator;
                    paintingNumericUpDown.Font = cellStyle.Font;
                    paintingNumericUpDown.Width = valBounds.Width;
                    paintingNumericUpDown.Height = valBounds.Height;
                    paintingNumericUpDown.RightToLeft = this.DataGridView.RightToLeft;
                    paintingNumericUpDown.Location = new Point(0, -paintingNumericUpDown.Height - 100);
                    paintingNumericUpDown.Text = formattedValue as string;

                    Color backColor;
                    if (PartPainted(paintParts, DataGridViewPaintParts.SelectionBackground) && cellSelected)
                    {
                        backColor = cellStyle.SelectionBackColor;
                    }
                    else
                    {
                        backColor = cellStyle.BackColor;
                    }
                    if (PartPainted(paintParts, DataGridViewPaintParts.Background))
                    {
                        if (backColor.A < 255)
                        {
                            // The NumericUpDown control does not support transparent back colors
                            backColor = Color.FromArgb(255, backColor);
                        }
                        paintingNumericUpDown.BackColor = backColor;
                    }
                    // Finally paint the NumericUpDown control
                    Rectangle srcRect = new Rectangle(0, 0, valBounds.Width, valBounds.Height);
                    if (srcRect.Width > 0 && srcRect.Height > 0)
                    {
                        paintingNumericUpDown.DrawToBitmap(renderingBitmap, srcRect);
                        graphics.DrawImage(renderingBitmap, new Rectangle(valBounds.Location, valBounds.Size),
                                           srcRect, GraphicsUnit.Pixel);
                    }
                }
                if (PartPainted(paintParts, DataGridViewPaintParts.ErrorIcon))
                {
                    // Paint the potential error icon on top of the NumericUpDown control
                    base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText,
                               cellStyle, advancedBorderStyle, DataGridViewPaintParts.ErrorIcon);
                }
            }
        }
Beispiel #4
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)
        {
            try
            {
                object o;
                o = value;

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

                //load Icons from resources
                //bells
                ImageList GridIcons = new ImageList();
                string    iconName;
                Icon      icon;

                //Inactive
                iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.InactiveBell.ico";
                icon     = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName));
                GridIcons.Images.Add(icon.ToBitmap());
                //Active
                iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.ActiveBell.ico";
                icon     = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName));
                GridIcons.Images.Add(icon.ToBitmap());
                //Ringing
                iconName = "AC.ExtendedRenderer.Toolkit.StdControls.Images.RingingBell.ico";
                icon     = new Icon(this.GetType().Assembly.GetManifestResourceStream(iconName));
                GridIcons.Images.Add(icon.ToBitmap());

                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(cellStyle.SelectionBackColor);
                    }

                    //erase background

                    if (c == 1)
                    {
                        //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height)
                        graphics.DrawImage(GridIcons.Images[1], ng);
                    }
                    else if (c == 2)
                    {
                        //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height)
                        graphics.DrawImage(GridIcons.Images[2], ng);
                    }
                    else
                    {
                        //graphics.FillRectangle(backBrush, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height)
                        graphics.DrawImage(GridIcons.Images[0], 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);
            }
        }
        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 s = ((string)value);
                if (string.IsNullOrWhiteSpace(s))
                {
                    return;
                }

                string[] values = s.Split(':');
                if (values.Length != 3)
                {
                    return;
                }

                float.TryParse(values[0], out float low);
                float.TryParse(values[1], out float mid);
                float.TryParse(values[2], out float max);

                float lowPercent = low / max;
                float midPercent = mid / max;
                // Draws the cell grid
                base.Paint(g, clipBounds, cellBounds,
                           rowIndex, cellState, value, formattedValue, errorText,
                           cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));
                cellBounds.Inflate(-2, -2);
                if (midPercent > 0.0)
                {
                    g.FillRectangle(SystemBrushes.GradientInactiveCaption, cellBounds.X, cellBounds.Y, midPercent * cellBounds.Width, cellBounds.Height);
                }

                if (lowPercent > 0.0)
                {
                    cellBounds.Inflate(-1, -1);
                    // Draw the progress bar and the text
                    g.FillRectangle(SystemBrushes.ActiveCaption, cellBounds.X, cellBounds.Y, lowPercent * cellBounds.Width, cellBounds.Height);
                    //g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreColorBrush, cellBounds.X + (cellBounds.Width / 2) - 5, cellBounds.Y + 2);
                }
                //else
                //{
                //    // draw the text
                //    if (this.DataGridView.CurrentRow.Index == rowIndex)
                //        g.DrawString(progressVal.ToString() + "%", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6, cellBounds.Y + 2);
                //    else
                //        g.DrawString(progressVal.ToString() + "%", cellStyle.Font, foreColorBrush, cellBounds.X + 6, cellBounds.Y + 2);
                //}
            }
            catch /*(Exception e) */ { }
        }
	// Methods
	public virtual DataGridViewAdvancedBorderStyle AdjustRowHeaderBorderStyle(DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedRow, bool isLastVisibleRow) {}
        /*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)
         * {
         *  if (value == null)
         *  {
         *      if (ProgressBarColors != null && ProgressBarColors.Count == 1)
         *      {
         *          g.FillRectangle(new SolidBrush(ProgressBarColors[0]), cellBounds);
         *          return;
         *      }
         *      value = 0;
         *  }
         *  List<int> Vals = new List<int>();
         *  try
         *  {
         *      Vals = (List<int>)value;
         *  }
         *  catch
         *  {
         *      Vals.Add(0);
         *      Vals.Add((int)value);
         *  }
         *
         *
         *  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));
         *
         *  float posX = cellBounds.X;
         *  float posY = cellBounds.Y;
         *
         *
         *  cellStyle.Padding = new Padding(2);
         *  var x = cellBounds.X + cellStyle.Padding.Left;
         *  var y = cellBounds.Y + cellStyle.Padding.Top;
         *  var w = cellBounds.Width - cellStyle.Padding.Right - cellStyle.Padding.Left;
         *  var h = cellBounds.Height - cellStyle.Padding.Top - cellStyle.Padding.Bottom;
         *  var brush = new SolidBrush(ProgressBarColor);
         *
         *
         *  var percent = 0.0;
         *  if (Vals.Count > 1) percent = Vals[1] / 10.0;
         *
         *  if (Vals.Count == 2 && Vals[0] == 0)
         *  {
         *      if (Vals[1] > 750)
         *          brush = new SolidBrush(Color.FromArgb(0x1E, 0xBA, 0x12));
         *      else if (Vals[1] > 350)
         *          brush = new SolidBrush(Color.LightBlue);
         *      else brush = new SolidBrush(Color.LightSalmon);
         *  }
         *  for (int i = 0; i < Vals.Count; i += 2)
         *  {
         *      if (Vals[i] < 0)
         *      {
         *          Vals[i + 1] += Vals[i];
         *          Vals[i] = -1;
         *      }
         *      if (Vals[i] + Vals[i + 1] > 1000)
         *          Vals[i + 1] = 1000 - Vals[i];
         *      var brush_ = brush;
         *      var h_ = h;
         *      var y_ = y;
         *      if (!(Vals.Count == 2 && Vals[0] == 0) && ProgressBarColors != null && ProgressBarColors.Count > i / 2)
         *      {
         *          brush_ = new SolidBrush(ProgressBarColors[i / 2]);
         *          if (ProgressBarColors[i / 2] == headerColor)
         *          {
         *              y_ = cellBounds.Y;
         *              h_ = 3;
         *          }
         *          if (ProgressBarColors[i / 2] == footerColor)
         *          {
         *              y_ = cellBounds.Y + cellBounds.Height - 7;
         *              h_ = 7;
         *          }
         *      }
         *      // Draw the progress
         *      g.FillRectangle(brush_,
         *          x + (int)(w * Vals[i] / 1000.0),
         *          y_,
         *          (Int32)(w * Vals[i + 1] / 1000.0),
         *          h_);
         *  }
         *
         #region
         *  if (Vals.Count == 2 && Vals[0] == 0)
         *  {
         *      float textWidth = TextRenderer.MeasureText(percent + "%", cellStyle.Font).Width;
         *      float textHeight = TextRenderer.MeasureText(percent + "%", cellStyle.Font).Height;
         *
         *
         *      posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
         *      posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
         *      g.DrawString(percent + "%", cellStyle.Font, foreColorBrush, posX, posY);
         *  }
         *  else
         *  {
         *      if (major != 0)
         *      {
         *          if (minor != 0)
         *          {
         *              var brush_ = new SolidBrush(minorColor);
         *              for (int i = 1; i < minor * major; i++)
         *              {
         *                  g.FillRectangle(brush_,
         *                      x + (float)(w * i / (minor * major * 1.0)),
         *                      cellBounds.Y - cellBounds.Height / 7,
         *                      1f,
         *                      2 * (cellBounds.Height / 7));
         *              }
         *          }
         *          {
         *              var brush_ = new SolidBrush(majorColor);
         *              for (int i = 1; i < major; i++)
         *              {
         *                  g.FillRectangle(brush_,
         *                      x + (float)(w * i / (1.0 * major)),
         *                      cellBounds.Y,
         *                      1,
         *                      cellBounds.Height);
         *              }
         *          }
         *      }
         *  }
         #endregion
         * }*/

        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)
        {
            // Draws the cell grid
            base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, (paintParts & ~DataGridViewPaintParts.ContentForeground));

            ProgressMap map = null;

            if (value is ProgressMap)
            {
                map = (ProgressMap)value;
            }
            else if (value is double || value is int)
            {
                map = new ProgressMap()
                {
                    max   = 100,
                    Cells = new List <ProgressCell> {
                        new ProgressCell {
                            start = 0, length = Convert.ToDouble(value)
                        }
                    },
                    SimpleProgress = true,
                }
            }
            ;
            if (map == null)
            {
                return;
            }

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

            cellStyle.Padding = new Padding(2);
            var x = cellBounds.X;
            var y = cellBounds.Y;
            var w = cellBounds.Width;
            var h = cellBounds.Height;

            if (!map.SimpleProgress)
            {
                x += cellStyle.Padding.Left;
                y += cellStyle.Padding.Top;
                w -= cellStyle.Padding.Left + cellStyle.Padding.Right;
                h -= cellStyle.Padding.Bottom + cellStyle.Padding.Top;
            }

            foreach (var cell in map.Cells)
            {
                var brush = new SolidBrush(ProgressBarColor);
                try
                {
                    if (map.Cells.Count == 1 &&
                        map.Cells[0].start == 0 &&
                        map.SimpleProgress &&
                        map.Cells[0].color == null)
                    {
                        brush.Dispose();
                        if (map.Cells[0].length / map.max > 0.750)
                        {
                            brush = new SolidBrush(Color.FromArgb(0x1E, 0xBA, 0x12));
                        }
                        else if (map.Cells[0].length / map.max > 0.350)
                        {
                            brush = new SolidBrush(Color.LightBlue);
                        }
                        else
                        {
                            brush = new SolidBrush(Color.LightSalmon);
                        }
                    }
                    if (cell.start < 0)
                    {
                        cell.length += cell.start;
                        cell.start   = -1;
                    }
                    if (cell.start + cell.length > map.max)
                    {
                        cell.length = map.max - cell.start;
                    }
                    var h_ = h;
                    var y_ = y;
                    if (cell.header)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(headerColor);
                        y_    = cellBounds.Y;
                        h_    = 3;
                    }
                    if (cell.footer)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(footerColor);
                        y_    = cellBounds.Y + cellBounds.Height - 7;
                        h_    = 7;
                    }
                    if (map.color != null)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(map.color.Value);
                    }
                    if (cell.color != null)
                    {
                        brush.Dispose();
                        brush = new SolidBrush(cell.color.Value);
                    }
                    var s = cell.start;
                    var d = cell.length;
                    if (map.RightToLeft)
                    {
                        s = map.max - (s + d);
                    }
                    // Draw the progress
                    g.FillRectangle(brush,
                                    x + (int)(w * s / map.max),
                                    y_,
                                    (int)(w * d / map.max),
                                    h_);
                }
                finally
                {
                    brush.Dispose();
                }
            }

            #region
            if (map.SimpleProgress || map.text != null)
            {
                var percent = "0%";
                if (map.text != null)
                {
                    percent = map.text;
                }
                else if (map.Cells.Count > 0)
                {
                    percent = (100 * map.Cells[0].length / map.max).ToString("0.#") + "%";
                }
                float textWidth  = TextRenderer.MeasureText(percent, cellStyle.Font).Width;
                float textHeight = TextRenderer.MeasureText(percent, cellStyle.Font).Height;


                posX = cellBounds.X + (cellBounds.Width / 2) - textWidth / 2;
                posY = cellBounds.Y + (cellBounds.Height / 2) - textHeight / 2;
                using (var foreColorBrush = new SolidBrush(cellStyle.ForeColor))
                    g.DrawString(percent, cellStyle.Font, foreColorBrush, posX, posY);
            }

            if (major != 0 && map.SimpleProgress == false)
            {
                if (minor != 0)
                {
                    using (var brush_ = new SolidBrush(minorColor))
                        for (int i = 1; i < minor * major; i++)
                        {
                            g.FillRectangle(brush_,
                                            x + (float)(w * i / (minor * major * 1.0)),
                                            cellBounds.Y - cellBounds.Height / 7,
                                            1f,
                                            2 * (cellBounds.Height / 7));
                        }
                }
                {
                    using (var brush_ = new SolidBrush(majorColor))
                        for (int i = 1; i < major; i++)
                        {
                            g.FillRectangle(brush_,
                                            x + (float)(w * i / (1.0 * major)),
                                            cellBounds.Y,
                                            1,
                                            cellBounds.Height);
                        }
                }
            }
            #endregion
        }
Beispiel #8
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 checkBox cell is disabled, so paint the border,
     // background, and disabled checkBox for the cell.
     if (!this.enabledValue)
     {
         // Draw the cell background, if specified.
         if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background)
         {
             Brush cellBackground = new SolidBrush(this.Selected ? cellStyle.SelectionBackColor : 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);
         }
         CheckState checkState = CheckState.Unchecked;
         if (formattedValue != null)
         {
             if (formattedValue is CheckState)
             {
                 checkState = (CheckState)formattedValue;
             }
             else if (formattedValue is bool)
             {
                 if ((bool)formattedValue)
                 {
                     checkState = CheckState.Checked;
                 }
             }
         }
         CheckBoxState state = checkState == CheckState.Checked ? CheckBoxState.CheckedDisabled : CheckBoxState.UncheckedDisabled;
         // Calculate the area in which to draw the checkBox.
         // force to unchecked!!
         Size  size   = CheckBoxRenderer.GetGlyphSize(graphics, state);
         Point center = new Point(cellBounds.X, cellBounds.Y);
         center.X += (cellBounds.Width - size.Width) / 2;
         center.Y += (cellBounds.Height - size.Height) / 2;
         // Draw the disabled checkBox.
         // We prevent painting of the checkbox if the Width,
         // plus a little padding, is too small.
         if (size.Width + 4 < cellBounds.Width)
         {
             CheckBoxRenderer.DrawCheckBox(graphics, center, state);
         }
     }
     else
     {
         // The checkBox 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 dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            try
            {
                DayColumn  dc  = this.OwningColumn as DayColumn;
                DateTime   now = DateTime.Now;
                SolidBrush HeaderColorBrush = Calendar.ct.ForeBrush;

                if (now.CompareTo(dc.StartTime) >= 0 && now.CompareTo(dc.EndTime) <= 0)
                {
                    LinearGradientBrush lgb = new LinearGradientBrush(cellBounds, Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                    graphics.FillRectangle(lgb, cellBounds);
                    HeaderColorBrush = new SolidBrush(Calendar.ct.SelectedForeColor);
                }
                else
                {
                    graphics.FillRectangle(new SolidBrush(Calendar.ct.BackColor), cellBounds);
                }

                graphics.DrawRectangle(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds);
                graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds.Left, cellBounds.Bottom - 1, cellBounds.Right, cellBounds.Bottom - 1);

                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;

                RectangleF rect = new RectangleF(cellBounds.Left, cellBounds.Top, cellBounds.Width, cellBounds.Height);
                graphics.DrawString(this.Value.ToString(), Calendar.ct.FontStd, HeaderColorBrush, rect, sf);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
        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);
                if (rowIndex == 1)
                {
                    graphics.DrawString(hour.ToString(), new Font("Arial", 15, FontStyle.Regular), Calendar.ct.ForeBrush, rectHour, sf);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
Beispiel #11
0
 protected override void PaintBorder(Graphics graphics, Rectangle clipBounds, Rectangle bounds, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle)
 {
     base.PaintBorder(graphics, clipBounds, bounds, cellStyle, advancedBorderStyle);
 }
	public virtual DataGridViewAdvancedBorderStyle AdjustCellBorderStyle(DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool singleVerticalBorderAdded, bool singleHorizontalBorderAdded, bool isFirstDisplayedColumn, bool isFirstDisplayedRow) {}
Beispiel #13
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, "", 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;
            }
        }
        protected override void Paint(
            Graphics graphics,
            Rectangle clipBounds,
            Rectangle cellBounds,
            int rowIndex,
            DataGridViewElementStates cellState,
            object value, //overide
            object formattedValue,
            string errorText,
            DataGridViewCellStyle cellStyle,
            DataGridViewAdvancedBorderStyle advancedBorderStyle,
            DataGridViewPaintParts paintParts)
        {
            // Call the base class method to paint the default cell appearance.
            if (this.userState == User.UserState.NONE)
            {
                value          = null;
                formattedValue = null;

                DataGridViewCellStyle newCellStyle = new DataGridViewCellStyle(cellStyle);
                newCellStyle.BackColor = this.DataGridView.BackgroundColor;

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

                return;
            }

            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                       value, null, 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.DarkBlue, newRect);
             * }
             */

            int       margin  = 5;
            Rectangle newRect = new Rectangle(cellBounds.X + margin,
                                              cellBounds.Y + margin, cellBounds.Height - margin * 2,
                                              cellBounds.Height - margin * 2);

            graphics.FillEllipse(new SolidBrush(User.stateColors[(int)userState]), newRect);
            graphics.DrawEllipse(Pens.Black, newRect);


            //
            // draw value
            //
            bool paint = true;
            bool computeContentBounds = false;

            Rectangle borderWidths = BorderWidths(advancedBorderStyle);
            Rectangle valBounds    = new Rectangle(cellBounds.X + cellBounds.Height,
                                                   cellBounds.Y, cellBounds.Width - cellBounds.Height,
                                                   cellBounds.Height);

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

            SolidBrush br;
            Point      ptCurrentCell   = this.DataGridView.CurrentCellAddress;
            bool       cellCurrent     = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex;
            bool       cellEdited      = cellCurrent && this.DataGridView.EditingControl != null;
            bool       cellSelected    = (cellState & DataGridViewElementStates.Selected) != 0;
            Rectangle  errorBounds     = valBounds;
            string     formattedString = formattedValue as string;


            byte DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft  = 0;
            byte DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginRight = 0;

            byte DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithWrapping    = 1;
            byte DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithoutWrapping = 2;
            byte DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginBottom             = 1;


            Rectangle resultBounds = Rectangle.Empty;

            if (formattedString != null && ((paint && !cellEdited) || computeContentBounds))
            {
                // Font independent margins
                int verticalTextMarginTop = cellStyle.WrapMode == DataGridViewTriState.True ? DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithWrapping : DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginTopWithoutWrapping;
                valBounds.Offset(DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft, verticalTextMarginTop);
                valBounds.Width  -= DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginLeft + DATAGRIDVIEWTEXTBOXCELL_horizontalTextMarginRight;
                valBounds.Height -= verticalTextMarginTop + DATAGRIDVIEWTEXTBOXCELL_verticalTextMarginBottom;
                if (valBounds.Width > 0 && valBounds.Height > 0)
                {
                    TextFormatFlags flags = ComputeTextFormatFlagsForCellStyleAlignment(this.DataGridView.RightToLeft == RightToLeft.Yes, cellStyle.Alignment, cellStyle.WrapMode);
                    if (paint)
                    {
                        if (PaintContentForeground(paintParts))
                        {
                            if ((flags & TextFormatFlags.SingleLine) != 0)
                            {
                                flags |= TextFormatFlags.EndEllipsis;
                            }
                            TextRenderer.DrawText(graphics,
                                                  formattedString,
                                                  cellStyle.Font,
                                                  valBounds,
                                                  cellSelected ? cellStyle.SelectionForeColor : cellStyle.ForeColor,
                                                  flags);
                        }
                    }
                    else
                    {
                        resultBounds = GetTextBounds(valBounds, formattedString, flags, cellStyle);
                    }
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// Paints red, green and orange based on the ToDo and IsBusy conditionals
        /// </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(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            setDefaultCellStyle();

            //if (this.OwningRow.Index < 0) return;

            //changed is not used
            //but could be used
            ICalculableRow Icalc = GetICalculable(rowIndex);

            bool? todo    = Icalc?.ToDo;
            bool? isBusy  = Icalc?.IsBusy;
            Color colr    = getColor(todo, isBusy);
            bool  changed = hasChanged(ref cellStyle, ref colr);



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

            //    base.DataGridView.NotifyCurrentCellDirty(true);
            //  base.DataGridView.ClearSelection();
        }
Beispiel #16
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,
                DataGridView.SingleVerticalBorderAdded(),
                DataGridView.SingleHorizontalBorderAdded());

            clipBounds = DataGridViewCellExHelper.GetSpannedCellClipBounds(ownerCell, cellBounds2,
                                                                           DataGridView.SingleVerticalBorderAdded(),
                                                                           DataGridView.SingleHorizontalBorderAdded());
            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);
                }
            }
        }
Beispiel #17
0
 private Rectangle NativeBorderWidths(DataGridViewAdvancedBorderStyle advancedBorderStyle)
 {
     return(base.BorderWidths(advancedBorderStyle));
 }
Beispiel #18
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);
 }
Beispiel #19
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, null, null, errorText, cellStyle, advancedBorderStyle, paintParts);

            Image img = GenerateHTMLImage(rowIndex, value, base.Selected);

            if (img != null)
            {
                graphics.DrawImage(img, cellBounds.Left, cellBounds.Top, cellBounds.Width, cellBounds.Height);                 //, img.Width, img.Height);
            }
        }
        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)
        {
            // paint the content cell
            if (rowIndex >= 0)
            {
                int[] sparks;
                if (value is int[])
                {
                    sparks = (int[])value;

                    if (sparks.Length > 0)
                    {
                        // let the base class draw the numeric contents
                        cellStyle.ForeColor = SignalColor.GetColorThreshold(sparks[sparks.Length - 1]);
                        base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, sparks[sparks.Length - 1],
                                   sparks[sparks.Length - 1].ToString(), errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.All);
                    }

                    using (Pen pen = new Pen(Color.Red))
                    {
                        float x0        = cellBounds.X + cellBounds.Width - RightPadding;
                        float xStepSize = ((cellBounds.Width - LeftPadding - RightPadding) / (float)AccessPoint.MaxDataPoints);

                        for (int i = sparks.Length - 1; i >= 0; i--)
                        {
                            float x = cellBounds.X + cellBounds.Width - RightPadding - (sparks.Length - i) * xStepSize;

                            // calculating Y value of each point... use range of -100 to -25 dBm
                            float y = cellBounds.Y + (-25f - sparks[i]) * ((float)cellBounds.Height / 75);

                            if (y < cellBounds.Y)
                            {
                                y = cellBounds.Y;
                            }
                            if (y > cellBounds.Y + cellBounds.Height - 1)
                            {
                                y = cellBounds.Y + cellBounds.Height - 1;
                            }

                            pen.Color = SignalColor.GetColorThreshold(sparks[i]);
                            graphics.DrawLine(pen, x0, y, x, y);

                            if (i == sparks.Length - 1)
                            {
                                // draw a dot at the last point to signify it is current..
                                pen.Color = Color.White;
                                graphics.DrawLine(pen, x0, y, x, y);
                            }

                            x0 = x;
                        }
                    }
                }
                else
                {
                    // let the base class draw the numeric contents
                    base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, null,
                               null, errorText, cellStyle, advancedBorderStyle, DataGridViewPaintParts.All);
                }
            }
            // paint the header row.
            else
            {
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value,
                           formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            }
        }
        /// <summary>
        /// Custom paints the cell. The base implementation of the DataGridViewTextBoxCell type is called first,
        /// dropping the icon error and content foreground parts. Those two parts are painted by this custom implementation.
        /// In this sample, the non-edited NumericUpDown control is painted by using a call to Control.DrawToBitmap. This is
        /// an easy solution for painting controls but it's not necessarily the most performant. An alternative would be to paint
        /// the NumericUpDown control piece by piece (text and up/down buttons).
        /// </summary>
        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));

            Point ptCurrentCell = this.DataGridView.CurrentCellAddress;
            bool  cellCurrent   = ptCurrentCell.X == this.ColumnIndex && ptCurrentCell.Y == rowIndex;
            bool  cellEdited    = cellCurrent && this.DataGridView.EditingControl != null;

            // If the cell is in editing mode, there is nothing else to paint
            if (!cellEdited)
            {
                if (PartPainted(paintParts, DataGridViewPaintParts.ContentForeground))
                {
                    // Paint a NumericUpDown control
                    // Take the borders into account
                    Rectangle borderWidths = BorderWidths(advancedBorderStyle);
                    Rectangle valBounds    = cellBounds;
                    valBounds.Offset(borderWidths.X, borderWidths.Y);
                    valBounds.Width  -= borderWidths.Right;
                    valBounds.Height -= borderWidths.Bottom;
                    // Also take the padding into account
                    if (cellStyle.Padding != Padding.Empty)
                    {
                        if (this.DataGridView.RightToLeft == RightToLeft.Yes)
                        {
                            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;
                    }
                    // Determine the NumericUpDown control location
                    valBounds = GetAdjustedEditingControlBounds(valBounds, cellStyle);

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

                    if (renderingBitmap.Width < valBounds.Width ||
                        renderingBitmap.Height < valBounds.Height)
                    {
                        // The static bitmap is too small, a bigger one needs to be allocated.
                        renderingBitmap.Dispose();
                        renderingBitmap = new Bitmap(valBounds.Width, valBounds.Height);
                    }
                    // Make sure the NumericUpDown control is parented to a visible control
                    if (paintingNumericUpDown.Parent == null || !paintingNumericUpDown.Parent.Visible)
                    {
                        if (paintingNumericUpDown.IsDisposed)
                        {
                            return;
                        }
                        paintingNumericUpDown.Parent = this.DataGridView;
                    }
                    // Set all the relevant properties
                    paintingNumericUpDown.TextAlign          = DataGridViewNumericUpDownCell.TranslateAlignment(cellStyle.Alignment);
                    paintingNumericUpDown.DecimalPlaces      = this.DecimalPlaces;
                    paintingNumericUpDown.ThousandsSeparator = this.ThousandsSeparator;
                    paintingNumericUpDown.Font        = cellStyle.Font;
                    paintingNumericUpDown.Width       = valBounds.Width;
                    paintingNumericUpDown.Height      = valBounds.Height;
                    paintingNumericUpDown.RightToLeft = this.DataGridView.RightToLeft;
                    paintingNumericUpDown.Location    = new Point(0, -paintingNumericUpDown.Height - 100);
                    paintingNumericUpDown.Text        = formattedValue as string;

                    Color backColor;
                    if (PartPainted(paintParts, DataGridViewPaintParts.SelectionBackground) && cellSelected)
                    {
                        backColor = cellStyle.SelectionBackColor;
                    }
                    else
                    {
                        backColor = cellStyle.BackColor;
                    }
                    if (PartPainted(paintParts, DataGridViewPaintParts.Background))
                    {
                        if (backColor.A < 255)
                        {
                            // The NumericUpDown control does not support transparent back colors
                            backColor = Color.FromArgb(255, backColor);
                        }
                        paintingNumericUpDown.BackColor = backColor;
                    }
                    // Finally paint the NumericUpDown control
                    Rectangle srcRect = new Rectangle(0, 0, valBounds.Width, valBounds.Height);
                    if (srcRect.Width > 0 && srcRect.Height > 0)
                    {
                        paintingNumericUpDown.DrawToBitmap(renderingBitmap, srcRect);
                        graphics.DrawImage(renderingBitmap, new Rectangle(valBounds.Location, valBounds.Size),
                                           srcRect, GraphicsUnit.Pixel);
                    }
                }
                if (PartPainted(paintParts, DataGridViewPaintParts.ErrorIcon))
                {
                    // Paint the potential error icon on top of the NumericUpDown control
                    base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText,
                               cellStyle, advancedBorderStyle, DataGridViewPaintParts.ErrorIcon);
                }
            }
        }
Beispiel #22
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
            {
                StringFormat sf = new StringFormat();
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;


                // Paint the Background and Header
                if (this.DateMode == DateMode.SevenDay)
                {
                    // Background
                    graphics.FillRectangle(new SolidBrush(Calendar.ct.DayBackColor), cellBounds);

                    // Header
                    if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                    {
                        // For Today we draw orange gradient
                        LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight), Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                        graphics.FillRectangle(lgb, cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight);
                    }
                    else
                    {
                        graphics.FillRectangle(new SolidBrush(Calendar.ct.BackColor), cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight);
                    }
                    graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds.Left, cellBounds.Top + headerHeight, cellBounds.Right, cellBounds.Top + headerHeight);
                    RectangleF r = new RectangleF(cellBounds.Left + 1, cellBounds.Top, cellBounds.Width - 2, headerHeight);
                    if (this.Selected && !bottomSelected)
                    {
                        graphics.FillRectangle(new SolidBrush(Calendar.ct.SelectionColor), cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight);
                        sf.Alignment = StringAlignment.Far;
                        graphics.DrawString(this.StartTime.ToLongDateString(), Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                    }
                    else
                    {
                        sf.Alignment = StringAlignment.Far;
                        if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                        {
                            graphics.DrawString(this.StartTime.ToLongDateString(), Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                        }
                        else
                        {
                            graphics.DrawString(this.StartTime.ToLongDateString(), Calendar.ct.FontStd, Calendar.ct.ForeBrush, r, sf);
                        }
                    }

                    if (this.RowIndex == 2 && this.ColumnIndex == 1) // If Sat/Sun cell drawing the bottom half
                    {
                        // Draw another cell
                        // Draw the middle line through the cell
                        graphics.DrawLine(new Pen(Calendar.ct.BorderBrush), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2) - 1, cellBounds.Right, cellBounds.Top + (int)(cellBounds.Height / 2) - 1);

                        // Header
                        if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                        {
                            // For Today we draw orange gradient
                            LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight), Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                            graphics.FillRectangle(lgb, cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight);
                        }
                        else
                        {
                            graphics.FillRectangle(new SolidBrush(Calendar.ct.BackColor), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight);
                        }
                        graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SeparatorDark)), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2) + headerHeight, cellBounds.Right, cellBounds.Top + (int)(cellBounds.Height / 2) + headerHeight);
                        r = new RectangleF(cellBounds.Left + 1, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width - 2, headerHeight);
                        if (this.Selected && bottomSelected)
                        {
                            graphics.FillRectangle(new SolidBrush(Calendar.ct.SelectionColor), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight);
                            sf.Alignment = StringAlignment.Far;
                            graphics.DrawString(this.StartTime.AddDays(1).ToLongDateString(), Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                        }
                        else
                        {
                            sf.Alignment = StringAlignment.Far;
                            if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                            {
                                graphics.DrawString(this.StartTime.AddDays(1).ToLongDateString(), Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                            }
                            else
                            {
                                graphics.DrawString(this.StartTime.AddDays(1).ToLongDateString(), Calendar.ct.FontStd, Calendar.ct.ForeBrush, r, sf);
                            }
                        }
                    }

                    // Border
                    graphics.DrawRectangle(new Pen(Calendar.ct.BorderBrush), cellBounds);
                }
                else // Month mode
                {
                    // Background
                    if (IsNewMonth)
                    {
                        graphics.FillRectangle(new SolidBrush(Calendar.ct.NewMonth), cellBounds);
                    }
                    else
                    {
                        graphics.FillRectangle(new SolidBrush(Calendar.ct.CurrentMonth), cellBounds);
                    }

                    // Header
                    RectangleF r          = new RectangleF(cellBounds.Left + 1, cellBounds.Top, cellBounds.Width - 2, headerHeight);
                    string     headerText = "";
                    if (this.StartTime.Day == 1 || (this.ColumnIndex == 0 && this.RowIndex == 0))
                    {
                        headerText = GetHeaderText(0);
                    }
                    else
                    {
                        headerText = this.StartTime.Day.ToString();
                    }

                    if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                    {
                        // For Today we draw orange gradient
                        LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight), Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                        graphics.FillRectangle(lgb, cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight);

                        graphics.DrawLine(new Pen(Calendar.ct.TodayGradientBrush), cellBounds.Left, cellBounds.Top + headerHeight, cellBounds.Right, cellBounds.Top + headerHeight);
                    }

                    if (this.Selected && !bottomSelected)
                    {
                        graphics.FillRectangle(new SolidBrush(Calendar.ct.SelectionColor), cellBounds.Left, cellBounds.Top, cellBounds.Width, headerHeight);
                        sf.Alignment = StringAlignment.Far;
                        graphics.DrawString(headerText, Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                        graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SelectionColor)), cellBounds.Left, cellBounds.Top + headerHeight, cellBounds.Right, cellBounds.Top + headerHeight);
                    }
                    else
                    {
                        sf.Alignment = StringAlignment.Far;
                        if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                        {
                            graphics.DrawString(headerText, Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                        }
                        else
                        {
                            graphics.DrawString(headerText, Calendar.ct.FontStd, Calendar.ct.ForeBrush, r, sf);
                        }
                    }

                    if (this.ColumnIndex == 5) // Sat/Sun column
                    {
                        // Draw another cell
                        // Draw the middle line through the cell
                        graphics.DrawLine(new Pen(Calendar.ct.BorderBrush), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2) - 1, cellBounds.Right, cellBounds.Top + (int)(cellBounds.Height / 2) - 1);

                        // If this is a new month paint the background
                        if (this.StartTime.AddDays(1).Day == 1)
                        {
                            graphics.FillRectangle(new SolidBrush(Calendar.ct.NewMonth), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, (int)(cellBounds.Height / 2));
                        }

                        // Header
                        r          = new RectangleF(cellBounds.Left + 1, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width - 2, headerHeight);
                        headerText = "";
                        if (this.StartTime.AddDays(1).Day == 1 || (this.ColumnIndex == 0 && this.RowIndex == 0))
                        {
                            headerText = GetHeaderText(1);
                        }
                        else
                        {
                            headerText = this.StartTime.AddDays(1).Day.ToString();
                        }

                        if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                        {
                            // For Today we draw orange gradient
                            LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight), Calendar.ct.HeaderLight, Calendar.ct.HeaderDark, LinearGradientMode.Vertical);
                            graphics.FillRectangle(lgb, cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight);
                            graphics.DrawLine(new Pen(Calendar.ct.TodayGradientBrush), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2) + headerHeight, cellBounds.Right, cellBounds.Top + (int)(cellBounds.Height / 2) + headerHeight);
                        }

                        if (this.Selected && bottomSelected)
                        {
                            graphics.FillRectangle(new SolidBrush(Calendar.ct.SelectionColor), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2), cellBounds.Width, headerHeight);
                            sf.Alignment = StringAlignment.Far;
                            graphics.DrawString(headerText, Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                            graphics.DrawLine(new Pen(new SolidBrush(Calendar.ct.SelectionColor)), cellBounds.Left, cellBounds.Top + (int)(cellBounds.Height / 2) + headerHeight, cellBounds.Right, cellBounds.Top + (int)(cellBounds.Height / 2) + headerHeight);
                        }
                        else
                        {
                            sf.Alignment = StringAlignment.Far;
                            if (this.StartTime.Year == DateTime.Now.Year && this.StartTime.Month == DateTime.Now.Month && this.StartTime.Day == DateTime.Now.Day)
                            {
                                graphics.DrawString(headerText, Calendar.ct.FontStd, new SolidBrush(Calendar.ct.SelectedForeColor), r, sf);
                            }
                            else
                            {
                                graphics.DrawString(headerText, Calendar.ct.FontStd, Calendar.ct.ForeBrush, r, sf);
                            }
                        }
                    }

                    // Border
                    graphics.DrawRectangle(new Pen(Calendar.ct.BorderBrush), cellBounds);
                } // Paint Background and Header

                // Paint items

                // Sort on StartTime
                List <CalendarItem> items = this.CalendarItems;
                for (int i = 0; i < items.Count; i++)
                {
                    for (int j = i; j < items.Count; j++)
                    {
                        if (items[i].StartTime.CompareTo(items[j].StartTime) > 0)
                        {
                            CalendarItem temp = items[i];
                            items[i] = items[j];
                            items[j] = temp;
                        }
                    }
                }

                if (!IsSpecialCell)
                {
                    // Form the text
                    string text = "";
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (this.DateMode == DateMode.SevenDay)
                        {
                            text += String.Format("{0} {1}  {2}\n", items[i].StartTime.ToShortTimeString().ToLower(), items[i].EndTime.ToShortTimeString().ToLower(), items[i].Description);
                        }
                        else
                        {
                            text += String.Format("{0}  {1}\n", items[i].StartTime.ToShortTimeString().ToLower(), items[i].Description);
                        }
                    }

                    RectangleF rect = new RectangleF(cellBounds.Left + 3, cellBounds.Top + headerHeight + 8, cellBounds.Width - 3, cellBounds.Height - headerHeight - 8);

                    //LinearGradientBrush lgb = new LinearGradientBrush(rect, ColorTable.getLightColor(items[i].Color, 110), items[i].Color, LinearGradientMode.Horizontal);
                    //graphics.FillRectangle(lgb, rect);

                    sf.Alignment     = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Near;
                    graphics.DrawString(text, Calendar.ct.FontStd, Calendar.ct.ForeBrush, rect, sf);
                }
                else
                {
                    string textSaturday = "";
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].StartTime.DayOfWeek != DayOfWeek.Saturday)
                        {
                            continue;
                        }
                        if (this.DateMode == DateMode.SevenDay)
                        {
                            textSaturday += String.Format("{0} {1}  {2}\n", items[i].StartTime.ToShortTimeString().ToLower(), items[i].EndTime.ToShortTimeString().ToLower(), items[i].Description);
                        }
                        else
                        {
                            textSaturday += String.Format("{0}  {1}\n", items[i].StartTime.ToShortTimeString().ToLower(), items[i].Description);
                        }
                    }

                    string textSunday = "";
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].StartTime.DayOfWeek != DayOfWeek.Sunday)
                        {
                            continue;
                        }
                        if (this.DateMode == DateMode.SevenDay)
                        {
                            textSunday += String.Format("{0} {1}  {2}\n", items[i].StartTime.ToShortTimeString().ToLower(), items[i].EndTime.ToShortTimeString().ToLower(), items[i].Description);
                        }
                        else
                        {
                            textSunday += String.Format("{0}  {1}\n", items[i].StartTime.ToShortTimeString().ToLower(), items[i].Description);
                        }
                    }

                    RectangleF rectSaturday = new RectangleF(cellBounds.Left + 3, cellBounds.Top + headerHeight + 8, cellBounds.Width - 3, (int)cellBounds.Height / 2 - headerHeight - 8);
                    RectangleF rectSunday   = new RectangleF(cellBounds.Left + 3, cellBounds.Top + (int)cellBounds.Height / 2 + headerHeight + 8, cellBounds.Width - 3, (int)cellBounds.Height / 2 - headerHeight - 8);
                    sf.Alignment     = StringAlignment.Near;
                    sf.LineAlignment = StringAlignment.Near;
                    graphics.DrawString(textSaturday, Calendar.ct.FontStd, Calendar.ct.ForeBrush, rectSaturday, sf);
                    graphics.DrawString(textSunday, Calendar.ct.FontStd, Calendar.ct.ForeBrush, rectSunday, sf);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
Beispiel #23
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.DrawImage(_image, cellBounds.X + 4, cellBounds.Y + 2);
 }
Beispiel #24
0
        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);

            if (this.IsInEditMode || string.IsNullOrWhiteSpace(Tips))
            {
                return;
            }
            graphics.DrawString(Tips, font, Brushes.Blue, cellBounds, sf);
        }
        /// <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 (!FilteringEnabled ||
                (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 (filterControlShowing)
                {
                    state = ComboBoxState.Pressed;
                }
                else if (filtered)
                {
                    state = ComboBoxState.Hot;
                }
                ComboBoxRenderer.DrawDropDownButton(
                    graphics, buttonBounds, state);

                Int32 pressedOffset = 0;
                if (filterControlShowing)
                {
                    pressedOffset = 1;
                }



                // If there is a filter in effect for the column, paint the
                // down arrow as an unfilled triangle. If there is no filter
                // in effect, paint the down arrow as a filled triangle.
                if (filtered)
                {
                    buttonBounds.Width  += 6;
                    buttonBounds.Height += 7;
                    buttonBounds.Offset(-2, -2);

                    if (false)
                    {
                        Pen drawPen = new Pen(Program.Colors.GetColor(GUIColors.ColorNames.Marked_BackColor));
                        graphics.DrawPolygon(drawPen, 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)
                        });
                    }
                    else
                    {
                        Brush drawBrush = new SolidBrush(Program.Colors.GetColor(GUIColors.ColorNames.Marked_BackColor));

                        graphics.FillPolygon(drawBrush, 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)
                        });
                    }
                }

                //else
                //{
                //    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)
                //    });
                //}
            }
            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 (filterControlShowing)
                {
                    state         = PushButtonState.Pressed;
                    pressedOffset = 1;
                }
                ButtonRenderer.DrawButton(graphics, buttonBounds, state);

                // If there is a filter in effect for the column, paint the
                // down arrow as an unfilled triangle. If there is no filter
                // in effect, paint the down arrow as a filled triangle.
                if (filtered)
                {
                    graphics.DrawPolygon(SystemPens.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)
                    });
                }
                else
                {
                    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)
                    });
                }
            }
        }
Beispiel #26
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)
        {
            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)
            {
                // Paint node glyphs
                if (node.IsExpanded)
                {
                    graphics.DrawImage(node._grid.rOpen, new Point(glyphRect.X - 5, glyphRect.Y));
                }
                else
                {
                    graphics.DrawImage(node._grid.rClosed, new Point(glyphRect.X - 5, glyphRect.Y));
                }
            }
        }
Beispiel #27
0
        /// <summary>
        /// Prepare for draw a cell.
        /// </summary>
        /// <param name="g">Graphics</param>
        /// <param name="cell">Cell to draw</param>
        /// <param name="s">String to draw</param>
        /// <param name="layoutRect">Rectangle for the layout</param>
        /// <param name="font">Used font</param>
        protected virtual void onPrepareDrawCell(Graphics g, DataGridViewCell cell, string s, RectangleF layoutRect, Font font)
        {
            // Set string format
            StringFormat format = new StringFormat();

            switch (cell.Style.Alignment)
            {
            case DataGridViewContentAlignment.BottomCenter:
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Far;
                break;

            case DataGridViewContentAlignment.MiddleCenter:
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                break;

            case DataGridViewContentAlignment.TopCenter:
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Near;
                break;

            case DataGridViewContentAlignment.BottomLeft:
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Far;
                break;

            case DataGridViewContentAlignment.MiddleLeft:
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Center;
                break;

            case DataGridViewContentAlignment.TopLeft:
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Near;
                break;

            case DataGridViewContentAlignment.BottomRight:
                format.Alignment     = StringAlignment.Far;
                format.LineAlignment = StringAlignment.Far;
                break;

            case DataGridViewContentAlignment.MiddleRight:
                format.Alignment     = StringAlignment.Far;
                format.LineAlignment = StringAlignment.Center;
                break;

            case DataGridViewContentAlignment.TopRight:
                format.Alignment     = StringAlignment.Far;
                format.LineAlignment = StringAlignment.Near;
                break;
            }
            // Prepare fore color
            SolidBrush brush        = null;
            bool       disposeBrush = false;

            if (cell.Style.ForeColor.ToArgb() == Color.FromArgb(0, 0, 0, 0).ToArgb())
            {
                brush = (SolidBrush)Brushes.Black;
            }
            else
            {
                if (cell.Style.ForeColor.IsNamedColor)
                {
                    brush = (SolidBrush)BrushHelper.GetBrush(cell.Style.ForeColor);
                }
                else
                {
                    brush        = new SolidBrush(cell.Style.ForeColor);
                    disposeBrush = true;
                }
            }
            // Prepare back color
            SolidBrush brushBack        = null;
            bool       disposeBrushBack = false;

            if (cell.Style.BackColor.ToArgb() == Color.FromArgb(0, 0, 0, 0).ToArgb())
            {
                brushBack = (SolidBrush)Brushes.White;
            }
            else
            {
                if (cell.Style.BackColor.IsNamedColor)
                {
                    brushBack = (SolidBrush)BrushHelper.GetBrush(cell.Style.BackColor);
                }
                else
                {
                    brushBack        = new SolidBrush(cell.Style.BackColor);
                    disposeBrushBack = true;
                }
            }
            // Prepare font
            Font f = (cell.Style.Font != null) ? cell.Style.Font : font;
            // Prepare box
            DataGridViewAdvancedBorderStyle borderStyle = new DataGridViewAdvancedBorderStyle();

            if (m_DrawCellBox)
            {
                borderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
            }
            // Draw
            onDrawCell(g, s, layoutRect, format, f, brush, brushBack, borderStyle);
            // Check to dispose brush
            if (disposeBrush)
            {
                brush.Dispose();
            }
            if (disposeBrushBack)
            {
                brushBack.Dispose();
            }
        }
	public virtual DataGridViewAdvancedBorderStyle AdjustColumnHeaderBorderStyle(DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStyleInput, DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder, bool isFirstDisplayedColumn, bool isLastVisibleColumn) {}
Beispiel #29
0
 /// <summary>
 /// Draw cell
 /// </summary>
 /// <param name="g">Graphics</param>
 /// <param name="s">String to draw</param>
 /// <param name="layoutRect">Rectangle for the layout</param>
 /// <param name="format">String format</param>
 /// <param name="font">Used font</param>
 /// <param name="brush">Fore brush</param>
 /// <param name="brushBack">Background brush</param>
 /// <param name="borderStyle">Border style</param>
 protected virtual void onDrawCell(Graphics g, string s, RectangleF layoutRect, StringFormat format, Font font, Brush brush, Brush brushBack, DataGridViewAdvancedBorderStyle borderStyle)
 {
     // Draw
     g.FillRectangle(brushBack, layoutRect);
     g.DrawString(s, font, brush, layoutRect, format);
     // Draw box
     drawBox(g, layoutRect, borderStyle);
 }
Beispiel #30
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);
        }
    }
Beispiel #31
0
 /// <summary>
 /// Draw column header
 /// </summary>
 /// <param name="g">Graphics</param>
 /// <param name="s">Column header label</param>
 /// <param name="layoutRect">Rectangle for the layout</param>
 /// <param name="format">Format for the string</param>
 /// <param name="font">Used font</param>
 /// <param name="borderStyle">Style for border</param>
 protected virtual void onDrawColumnHeader(Graphics g, string s, RectangleF layoutRect, StringFormat format, Font font, DataGridViewAdvancedBorderStyle borderStyle)
 {
     g.DrawString(s, font, Brushes.Black, layoutRect, format);
     // Draw box
     drawBox(g, layoutRect, borderStyle);
 }
        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);

                // Replace special value placeholders
                var editedMessage = _text.Replace(MessageSpecialValue.CurrentValue, Value.ToString())
                                         .Replace(MessageSpecialValue.Maximum, Maximum.ToString())
                                         .Replace(MessageSpecialValue.Minimum, Minimum.ToString());

                // 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
            }
        }
        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 (null == value)
            {
                value = 0;
            }
            var vVal          = value;
            int progressValue = (int)Convert.ChangeType(vVal, typeof(int));

            //double ProgressValue = 0;
            //if (value != null) ProgressValue = (double)value;

            float Percentage = ((float)progressValue / 100.0f); //현재 진행률 계산(float형)

            Brush backColorBrush = new SolidBrush(cellStyle.BackColor);
            Brush foreColorBrush = new SolidBrush(cellStyle.ForeColor);

            //Progress Color 지정
            Brush ProgressColorBrush = new SolidBrush(Color.FromArgb(2, 148, 202));

            //Progressbar 시작위치(포인트), 크기 설정
            Rectangle ProgressBarBounds = new Rectangle();

            ProgressBarBounds.X      = cellBounds.X + 2;                                     //가로 시작 위치(왼쪽 여백)
            ProgressBarBounds.Y      = cellBounds.Y + (int)(cellBounds.Height / 4);          //세로 시작 위치(위쪽 여백)
            ProgressBarBounds.Width  = Convert.ToInt32(Percentage * (cellBounds.Width - 4)); //ProgressBar 길이(오른쪽 여백)
            ProgressBarBounds.Height = (int)(cellBounds.Height * 0.55);                      //높이(아래쪽 여백)

            //Progressbar 진행률 Text 위치 설정
            PointF ProgressStrPoint = new PointF();

            ProgressStrPoint.X = (float)cellBounds.X + (cellBounds.Width / 2) - 12;   //Cell 텍스트 시작 위치
            ProgressStrPoint.Y = (float)cellBounds.Y + (cellBounds.Height / 2) - 8;


            //           Color textColor = cellStyle.ForeColor;
            Color textColor = cellStyle.ForeColor;

            if ((elementState & DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
            {
                textColor = cellStyle.SelectionForeColor;
            }

            using (SolidBrush brush = new SolidBrush(textColor))
            //            using (SolidBrush brush = new SolidBrush(Color.FromArgb(65, 90, 140)))
            {
                //Default Cell을 그린다.
                base.Paint(
                    graphics,
                    clipBounds,
                    cellBounds,
                    rowIndex,
                    elementState,
                    value,
                    formattedValue,
                    errorText,
                    cellStyle,
                    advancedBorderStyle,
                    paintParts);

                if (Percentage >= 1.0)
                {
                    ProgressStrPoint.X = (float)cellBounds.X + (cellBounds.Width / 2) - 24;   //Cell 텍스트 시작 위치
                    //                     if (this.DataGridView.CurrentRow.Index == rowIndex)  //현재 Row
                    //                         graphics.DrawString("대기중..", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), ProgressStrPoint);
                    //                     else
                    graphics.DrawString("100%", cellStyle.Font, brush, ProgressStrPoint);
                }
                else if (Percentage >= 0.0)
                {
                    //ProgressBar를 그린다
                    graphics.FillRectangle(ProgressColorBrush, ProgressBarBounds);
                    graphics.DrawString(progressValue.ToString() + "%", cellStyle.Font, brush, ProgressStrPoint);
                }
                else
                {
                    ///****************************************
                    /// ProgressBar가 시작전일때(준비중, 대기중)
                    /// Row 선택됨에 따라 Font Color 변경
                    ///****************************************


                    if (this.DataGridView.CurrentRow != null)
                    {
                        ProgressStrPoint.X = (float)cellBounds.X + (cellBounds.Width / 2) - 24;   //Cell 텍스트 시작 위치
                        //                     if (this.DataGridView.CurrentRow.Index == rowIndex)  //현재 Row
                        //                         graphics.DrawString("대기중..", cellStyle.Font, new SolidBrush(cellStyle.SelectionForeColor), ProgressStrPoint);
                        //                     else
                        graphics.DrawString("0%", cellStyle.Font, brush, ProgressStrPoint);
                    }
                }
            }
        }
	// Constructors
	public DataGridViewCellPaintingEventArgs(DataGridView dataGridView, System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts 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, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
     if (DataGridView != null && this.DataGridView.ReadOnly)
     {
         //Vérifie que le texte rentre dans la fenêtre
         SizeF sz = graphics.MeasureString(value.ToString(), DataGridView.Font);
         if (sz.Width > cellBounds.Width || sz.Height > cellBounds.Height)
         {
             Point[] pts = new Point[] {
                 new Point(cellBounds.Right - 10, cellBounds.Bottom - 1),
                 new Point(cellBounds.Right - 1, cellBounds.Bottom - 10),
                 new Point(cellBounds.Right - 1, cellBounds.Bottom - 1)
             };
             graphics.FillPolygon(Brushes.LightGray, pts);
         }
     }
 }
Beispiel #36
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);
            }
        }
        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)
        {
            if (_Color != Color.Transparent)
            {
                SmoothingMode mode = graphics.SmoothingMode;//跟妳說喔,NotNetBar很機車喔,如果你把SmoothingMode改掉沒改回去,格線會亂亂劃喔。
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, null, null, errorText, cellStyle, advancedBorderStyle, paintParts);

                int w = cellBounds.Height - 9,
                    x = cellBounds.X + 3,
                    y = cellBounds.Y + 4;
                Color[]    myColors    = { _Color, Color.White, _Color, _Color };
                float[]    myPositions = { 0.0f, 0.05f, 0.6f, 1.0f };
                ColorBlend myBlend     = new ColorBlend();
                myBlend.Colors    = myColors;
                myBlend.Positions = myPositions;
                using (LinearGradientBrush brush = new LinearGradientBrush(new Point(x, y), new Point(x + w, y + w), Color.White, _Color))
                {
                    brush.InterpolationColors = myBlend;
                    brush.GammaCorrection     = true;
                    graphics.FillRectangle(brush, x, y, w, w);
                }
                graphics.DrawRectangle(new Pen(Color.Black), x, y, w, w);

                cellBounds             = new System.Drawing.Rectangle(cellBounds.X + cellBounds.Height - 4, cellBounds.Y, cellBounds.Width - cellBounds.Height + 4, cellBounds.Height);
                graphics.SmoothingMode = mode;
            }
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
        }