Beispiel #1
0
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            //base.Paint(g, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            Brush textColor = CellFunctions.DrawPlainBackground(this, this.Enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

            //float y = (cellBounds.Height - textSize.Height) / 2 + cellBounds.Y;
            SizeF textSize = g.MeasureString(this.Value as String, _parent.Font);

            if ((textSize.Width + 13) > cellBounds.Width)
            {
                g.DrawString(this.Value as String, _parent.Font, textColor, new RectangleF(new PointF(cellBounds.X + 3.0f, cellBounds.Y), new SizeF(cellBounds.Width - 13, cellBounds.Height)));
            }
            else
            {
                float y = CellFunctions.TextCenterYInRact(cellBounds, g, _parent.Font);
                g.DrawString(this.Value as String, _parent.Font, textColor, new PointF(cellBounds.X + 3.0f, y));
            }
            float margin     = (cellBounds.Height - 10) / 2;
            float pathTop    = cellBounds.Y + margin; //path의 height를 10으로 한다.
            float PathBottom = cellBounds.Y + cellBounds.Height - margin;

            g.FillPath(Brushes.Gainsboro, new GraphicsPath(
                           new PointF[] {
                new PointF(cellBounds.Right - 10, pathTop),
                new PointF(cellBounds.Right - 10, PathBottom),
                new PointF(cellBounds.Right - 3, (pathTop + PathBottom) / 2)
            },
                           new byte[] {
                (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line
            }, FillMode.Winding));
        }
 public void OnPaint(DataGridViewCellPaintingEventArgs e)
 {
     if (_enabled && _visible)
     {
         Point pt = this.DataGridView.PointToClient(Control.MousePosition);
         if (e.CellBounds.Contains(pt) && _visible && _enabled)
         {
             CellFunctions.DrawPlainBackground(this, this.Enabled, e.CellBounds, e.Graphics, e.RowIndex, true, this.DataGridView.GridColor);
             //_refreshTimer.Start();
         }
         else
         {
             CellFunctions.DrawPlainBackground(this, this.Enabled, e.CellBounds, e.Graphics, e.RowIndex, false, this.DataGridView.GridColor);
             //_refreshTimer.Stop();
         }
         PaintCell(e.CellBounds, e.Graphics);
         e.Handled = true;
     }
 }
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            if (_visible)
            {
                if (_enabled == false)
                {
                    g.FillRectangle(new SolidBrush(Color.WhiteSmoke), cellBounds);
                    //g.DrawRectangle(new Pen(Color.Gray, 0.5f), cellBounds);
                    //int textY = CellFunctions.TextCenterYInRact(cellBounds, g, _font);// cellBounds.Y + (int)((cellBounds.Height - textSize.Height) / 2.0);
                    Point textPos = CellFunctions.TextCenterInRact(cellBounds, g, _font, this.Text);
                    g.DrawString(Text, _font, _fontColor, textPos.X, textPos.Y);
                    g.DrawLine(new Pen(_parent.GridColor, 0.1f), cellBounds.X, cellBounds.Y + cellBounds.Height - 1, cellBounds.X + cellBounds.Width, cellBounds.Y + cellBounds.Height - 1);
                    g.DrawLine(new Pen(Color.FromArgb(200, 200, 200), 0.1f), cellBounds.X + cellBounds.Width - 1, cellBounds.Y, cellBounds.X + cellBounds.Width - 1, cellBounds.Y + cellBounds.Height - 1);
                }
                else
                {
                    Brush textColor = CellFunctions.DrawLensBack(this, cellBounds, g, _parent.GridColor, this.Selected, _enabled);
                    Point pt        = CellFunctions.TextCenterInRact(cellBounds, g, _parent.Font, this.Text);
                    g.DrawString(this.Text as String, _parent.Font, textColor, pt.X, pt.Y);
                }
            }
            else
            {
                CellFunctions.DrawPlainBackground(this, Enabled, cellBounds, g, rowIndex, Selected, DataGridView.GridColor);
            }
            paintParts = DataGridViewPaintParts.None;

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

            /*
             * g.FillPath(Brushes.Gainsboro, new GraphicsPath(
             *  new PointF[]{
             *      new PointF(e.CellBounds.Right-10, e.CellBounds.Top+4),
             *      new PointF(e.CellBounds.Right-10, e.CellBounds.Bottom -4),
             *      new PointF(e.CellBounds.Right-3, (e.CellBounds.Top + e.CellBounds.Bottom)/2)},
             *  new byte[]{
             *      (byte)PathPointType.Start,(byte)PathPointType.Line,(byte)PathPointType.Line}, FillMode.Winding));
             */
            //e.Handled = true;
        }
        void PaintCell(Rectangle initCellBounds, Graphics g)
        {
            System.Drawing.Drawing2D.GraphicsContainer con = g.BeginContainer();
            Rectangle cellBounds = initCellBounds;

            //Rectangle drawRect = initCellBounds;
            #region test

            /*
             * if (ColSpan > 1)
             * {
             *  cellBounds = new Rectangle(cellBounds.X, cellBounds.Y, 0, cellBounds.Height);
             *  cellBounds.Width = _parent.GetColumnSize(this.ColumnIndex, ColSpan);
             *
             * }
             * if (RowSpan > 1)
             * {
             *  int firstRow = RowIndex;
             *  int lastRow = RowIndex + RowSpan-1;
             *  int minus = 0;
             *  if (RowIndex < _parent.FirstDisplayedCell.RowIndex)
             *  {
             *      firstRow = _parent.FirstDisplayedCell.RowIndex;
             *      minus = _parent.GetRowsSize(RowIndex, firstRow - RowIndex);// RowIndex - _parent.FirstDisplayedCell.RowIndex;
             *  }
             *  if (lastRow > (_parent.FirstDisplayedCell.RowIndex + _parent.DisplayedRowCount(true)))
             *  {
             *      lastRow = (_parent.FirstDisplayedCell.RowIndex + _parent.DisplayedRowCount(true))-1;
             *  }
             *  Rectangle firstRect = _parent.GetCellDisplayRectangle(this.ColumnIndex, firstRow, true);
             *  Rectangle lastRect = _parent.GetCellDisplayRectangle(this.ColumnIndex, lastRow, true);
             *  drawRect = new Rectangle(firstRect.X, firstRect.Y, firstRect.Width, lastRect.Y - firstRect.Y + lastRect.Height);
             *
             *  cellBounds = new Rectangle(drawRect.X, drawRect.Y-minus, drawRect.Width, _parent.GetRowsSize(RowIndex, RowSpan));
             *
             * }
             *
             * if (ColSpan > 1 || RowSpan > 1)
             * {
             *  CellFunctions.DrawPlainBackground(this, _enabled, drawRect, g, this.RowIndex, false, _parent.GridColor);
             *
             *
             * }
             * else
             * {
             *  CellFunctions.DrawPlainBackground(this, _enabled, drawRect, g, this.RowIndex, this.Selected, _parent.GridColor);
             * }
             */
            #endregion

            int textY      = CellFunctions.TextCenterYInRact(cellBounds, g, _font);// cellBounds.Y + (int)((cellBounds.Height - textSize.Height) / 2.0);
            int textMargin = _textMargin;

            SizeF textSize = g.MeasureString(Text, _font);
            textSize.Width -= textMargin;

            if (textY < cellBounds.Y) //|| (textY + textSize.Height) > (cellBounds.Y + cellBounds.Height))
            {
                //don't draw text..
            }
            else
            {
                if (TextViewMode == TextViewModes.ResizeForCellWid)
                {
                    CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

                    DrawStringResizedForCellWid(textSize, cellBounds, textMargin, textY, g);
                }
                else if (TextViewMode == TextViewModes.MultiLines)
                {
                    int newHeight = (OwningRow as EasyGridRow).SetRowHeight();
                    cellBounds.Height = newHeight;
                    CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

                    DrawStringMultiLines(cellBounds, textMargin, textY, g);
                }
                else //default.. single line..
                {
                    CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);
                    DrawSingleLine(cellBounds, g, textSize, textY, textMargin);
                    //DrawStringNormal(size, cellBounds, textMargin, textY, g);
                    //g.DrawString(Text, _font, _fontColor, cellBounds.X + 2, textY);
                }
                //int y = drawRect.Y + drawRect.Height - 1;
                //g.DrawLine(new Pen(_parent.GridColor, 0.1f), drawRect.X, y, drawRect.X + drawRect.Width, y);
            }

            g.EndContainer(con);
            g.Flush();
        }
Beispiel #5
0
        protected virtual void PaintCell(Graphics g, Rectangle cellBounds)
        {
            //Graphics g = Graphics.FromHdcInternal(_hdc);
            // if (_items.Count == 0) return;

            //g.DrawString(_items.RefCount.ToString(), _font, Brushes.Blue, 10, cellBounds.Y);
            //g.FillRectangle(Brushes.Red, new Rectangle(cellBounds.X + 0, cellBounds.Y + 0, 10, 10));
            Brush fontColor = CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

            //g.FillRectangle(Brushes.Blue, new Rectangle(cellBounds.X + 0, cellBounds.Y + 0, 10, 10));

            if (_orientation == EasyGridRadioBoxOrientation.Horizontal)
            {
                //Point p = new Point(cellBounds.Left, cellBounds.Top+3);

                SizeF textSize   = TextSize(_items[0].Text, g);
                int   textOffset = (textSize.Height < _images[0].Height) ? (int)((_images[0].Height - textSize.Height)) / 2 : 0;
                int   imgOffset  = (textSize.Height >= _images[0].Height) ? (int)(textSize.Height - (_images[0].Height)) / 2 : 0;

                int textY = cellBounds.Y + (int)((cellBounds.Height - textSize.Height) / 2.0);

                int imgY = cellBounds.Y + (int)((cellBounds.Height - _images[0].Height) / 2.0);
                int top  = (textY < imgY) ? textY : imgY;
                //int bottom = (textSize.Height < _images[0].Height) ? _images[0].Height : (int) textSize.Height;
                int x = cellBounds.Left + 3;
                //Point p = new Point(cellBounds.Left, textY);
                //float height = (textSize.Height < _images[0].Height) ? _images[0].Height : (textSize.Height);


                for (int i = 0; i < _items.Count; i++)
                {
                    DrawCheckBox(g, x, top, _items[i], textOffset, imgOffset, fontColor);


                    x += _items[i].Width + 3;
                }
            }
            else if (_orientation == EasyGridRadioBoxOrientation.Vertical)
            {
                SizeF textSize   = TextSize(_items[0].Text, g);
                int   textOffset = (textSize.Height < _images[0].Height) ? (int)((_images[0].Height - textSize.Height)) / 2 : 0;
                int   imgOffset  = (textSize.Height >= _images[0].Height) ? (int)(textSize.Height - (_images[0].Height)) / 2 : 0;
                float height     = (textSize.Height < _images[0].Height) ? _images[0].Height : (textSize.Height);
                int   top        = cellBounds.Y + (int)((cellBounds.Height - height * _items.Count) / 2.0);
                int   bottom     = top + (int)(height * _items.Count);

                int y        = top;
                int x        = cellBounds.X + 3;
                int imgWidth = _images[0].Width + 2;

                for (int i = 0; i < _items.Count; i++)
                {
                    y = top + (int)(height * i);
                    DrawCheckBox(g, x, y, _items[i], textOffset, imgOffset, fontColor);
                }
            }
            else
            {
                SizeF textSize   = TextSize(_items[0].Text, g);
                int   textOffset = (textSize.Height < _images[0].Height) ? (int)((_images[0].Height - textSize.Height)) / 2 : 0;
                int   imgOffset  = (textSize.Height >= _images[0].Height) ? (int)(textSize.Height - (_images[0].Height)) / 2 : 0;
                float height     = (textSize.Height < _images[0].Height) ? _images[0].Height : (textSize.Height);

                int maxCount = (_items.Count < 2) ? _items.Count : 2;
                int top      = cellBounds.Y + (int)((cellBounds.Height - height * maxCount) / 2.0);
                int bottom   = top + (int)(height * maxCount);

                int y        = top;
                int x        = cellBounds.X + 3;
                int imgWidth = _images[0].Width + 2;

                for (int i = 0; i < _items.Count; i++)
                {
                    y = top + (int)(height * (i % 2));
                    DrawCheckBox(g, x, y, _items[i], textOffset, imgOffset, fontColor);

                    if (i % 2 == 1)
                    {
                        x += _items[i].Width + 5;
                    }
                }
            }
        }