protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts)
        {
            bool    canParse = true;
            decimal val      = 0m;

            try
            {
                val = Convert.ToDecimal(value);
            }
            catch
            {
                canParse = false;
            }

            DataGridViewPercentColumn col = this.OwningColumn as DataGridViewPercentColumn;

            if (canParse && col.TotalCount > 0)
            {
                decimal decv = val / col.TotalCount;
                if (decv > 1)
                {
                    decv = 1;
                }
                if (decv < 0)
                {
                    decv = 0;
                }
                Brush bs = new SolidBrush(cellStyle.BackColor);
                //Brush bs2 = new SolidBrush(Color.YellowGreen);
                Brush bs2      = new SolidBrush(Color.Red);
                Brush bsstring = new SolidBrush(cellStyle.ForeColor);
                if ((cellState & System.Windows.Forms.DataGridViewElementStates.Selected) == System.Windows.Forms.DataGridViewElementStates.Selected)
                {
                    bs       = new SolidBrush(cellStyle.SelectionBackColor);
                    bsstring = new SolidBrush(cellStyle.SelectionForeColor);
                }
                //if (decv < 0.75m)
                //{
                //    if (decv < 0.2m)
                //    {
                //        bs2 = new SolidBrush(Color.Red);
                //    }
                //    else
                //    {
                //        bs2 = new SolidBrush(Color.Orange);
                //    }
                //}
                Pen p = new Pen(DataGridView.GridColor, 1);
                graphics.FillRectangle(bs, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height);
                graphics.FillRectangle(bs2, cellBounds.X + 1, cellBounds.Y + 1, (float)((cellBounds.Width - 3) * decv), cellBounds.Height - 3);
                graphics.DrawLine(p, cellBounds.X, cellBounds.Y + cellBounds.Height - 1, cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1);
                graphics.DrawLine(p, cellBounds.X + cellBounds.Width - 1, cellBounds.Y, cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1);
                if (cellBounds.Width > cellStyle.Font.Size * 4)
                {
                    string showString = null;
                    if (col.ShowTotal)
                    {
                        showString = GetNumberString(val) + "/" + GetNumberString(col.TotalCount);
                    }
                    else
                    {
                        showString = GetNumberString(val);
                    }
                    graphics.DrawString(showString, cellStyle.Font, bsstring, cellBounds.X + 4, cellBounds.Y + 4);
                }
            }
            else
            {
                Brush bs = new SolidBrush(cellStyle.BackColor);
                if ((cellState & System.Windows.Forms.DataGridViewElementStates.Selected) == System.Windows.Forms.DataGridViewElementStates.Selected)
                {
                    bs = new SolidBrush(cellStyle.SelectionBackColor);
                }
                graphics.FillRectangle(bs, cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height);
            }
        }
Esempio n. 2
0
 protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, System.Windows.Forms.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, System.Windows.Forms.DataGridViewCellStyle cellStyle, System.Windows.Forms.DataGridViewAdvancedBorderStyle advancedBorderStyle, System.Windows.Forms.DataGridViewPaintParts paintParts)
 {
     if (this.OwningColumn != null && !value.IsNullOrEmpty())
     {
         NjitTextBoxColumn column = (this.OwningColumn as NjitTextBoxColumn);
         if (column.TextBoxExtended.AutoSeparateDigits)
         {
             if (value.ToString().Contains(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString()))
             {
                 value = value.ToString().Replace(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator[0].ToString(), "");
             }
             formattedValue = Njit.Common.Helpers.NumbersHelper.InsertComma(value.ToString());
         }
     }
     base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
 }