Ejemplo n.º 1
0
        private static void DataGridView_OnCellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                e.PaintBackground(e.CellBounds, true);
                //e.Graphics.FillRectangle(Brushes.Red, e.CellBounds);

                e.PaintContent(e.CellBounds);
                //(((System.Windows.Forms.Control)(sender)).TopLevelControl).GetType().Name
                e.Graphics.DrawLine(StyleSettings.Pen_CabecalhoGrid_Div1
                                    , e.CellBounds.X + e.CellBounds.Width - 2
                                    , 3
                                    , e.CellBounds.X + e.CellBounds.Width - 2
                                    , e.CellBounds.Height - 2
                                    );

                System.Windows.Forms.DataGridView grid = (System.Windows.Forms.DataGridView)sender;

                if (grid.Columns[e.ColumnIndex].Tag != null)
                {
                    System.Drawing.Bitmap imagem = new System.Drawing.Bitmap(Properties.Resources.Ico_Filtrar_8x8);
                    e.Graphics.DrawImage(imagem, new System.Drawing.Rectangle(e.CellBounds.X + e.CellBounds.Width - imagem.Width - StyleSettings.DeslocaImagem_Botao, e.CellBounds.Y + StyleSettings.DeslocaImagem_Botao, imagem.Width, imagem.Height));
                    ((FilterSettings.Filtro)grid.Columns[e.ColumnIndex].Tag).Nome = grid.Columns[e.ColumnIndex].HeaderText;
                    ((FilterSettings.Filtro)grid.Columns[e.ColumnIndex].Tag).PosicaoCabecalhoGrid = e.CellBounds;
                }

                e.Handled = true;
            }
        }
    private void PaintColumnHeader(System.Windows.Forms.DataGridViewCellPaintingEventArgs e, System.Drawing.Color color)
    {
        LinearGradientBrush backBrush = new LinearGradientBrush(new System.Drawing.Point(0, 0), new System.Drawing.Point(100, 100), color, color);

        e.Graphics.FillRectangle(backBrush, e.CellBounds);
        DataGridViewPaintParts parts = (DataGridViewPaintParts.All & ~DataGridViewPaintParts.Background);

        e.AdvancedBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.None;
        e.AdvancedBorderStyle.Left  = DataGridViewAdvancedCellBorderStyle.None;
        e.Paint(e.ClipBounds, parts);
        e.Handled = true;
    }
 protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
 {
     if (e.Value == System.DBNull.Value && this.DefaultCellStyle.NullValue != null)
     {
         System.Windows.Forms.DataGridViewCellStyle style = e.CellStyle;
         using (Font fontItl = new Font(this.Font.FontFamily, this.Font.Size - 0.1f, FontStyle.Italic, this.Font.Unit))
         {
             style.Font      = fontItl;
             style.ForeColor = System.Drawing.Color.Gray;
             e.CellStyle.ApplyStyle(style);
         }
     }
     base.OnCellPainting(e);
 }
Ejemplo n.º 4
0
 protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
 {
     if (bDragging && hti != null && hti.RowIndex != -1 &&
         e.RowIndex == hti.RowIndex)
     {
         //
         // draw the indicator
         //
         Pen p = new Pen(Color.FromArgb(0, 0, 215));
         p.Width = 4;
         e.Graphics.DrawLine(p, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Right, e.CellBounds.Top);
     }
     base.OnCellPainting(e);
 }
Ejemplo n.º 5
0
        protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
        {
            Color mLinearColor1    = Color.FromArgb(247, 251, 254);
            Color mLinearColor2    = Color.FromArgb(213, 231, 255);
            Color mGridColor       = Color.FromArgb(120, 147, 191); //网格线的颜色
            Color mHasFocusedColor = Color.DarkCyan;                //控件的焦点框颜色


            Rectangle           Rect = new Rectangle(e.CellBounds.X - 1, e.CellBounds.Y, e.CellBounds.Width, e.CellBounds.Height - 1);
            LinearGradientBrush LinearGradientBrushs = new LinearGradientBrush(Rect, mLinearColor1, mLinearColor2, LinearGradientMode.Vertical);

            try
            {
                if (e.RowIndex == -1 || e.ColumnIndex == -1)
                {
                    e.Graphics.FillRectangle(LinearGradientBrushs, Rect);
                    e.Graphics.DrawRectangle(new Pen(mGridColor), Rect);
                    e.PaintContent(e.CellBounds);
                    e.Handled = true;
                }
            }

            catch
            { }
            finally
            {
                if (LinearGradientBrushs != null)
                {
                    LinearGradientBrushs.Dispose();
                }
            }

            /*不显示焦点颜色*/
            //this.DefaultCellStyle.SelectionBackColor = Color.Transparent ;
            //this.DefaultCellStyle.SelectionForeColor  = Color.Black ;


            base.OnCellPainting(e);
        }
Ejemplo n.º 6
0
            protected override void OnCellPainting(System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
            {
                if (e.ColumnIndex >= 0 && e.RowIndex == -1)
                {
                    string text = this.Columns[e.ColumnIndex].HeaderText;

                    //Getting the width and height of the text, which we are going to write
                    double columnTextWidth  = e.Graphics.MeasureString(text, e.CellStyle.Font).Width;
                    double columnTextHeight = e.Graphics.MeasureString(text, e.CellStyle.Font).Height;

                    // Erase the cell.
                    using (System.Drawing.Brush backColorBrush = new System.Drawing.SolidBrush(e.CellStyle.BackColor))
                    {
                        e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
                    }

                    // only need 1 bottom line...
                    e.Graphics.DrawLine(System.Drawing.Pens.DarkGray, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right, e.CellBounds.Bottom - 1);

                    // two top lines...
                    e.Graphics.DrawLine(System.Drawing.Pens.DarkGray, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Right, e.CellBounds.Top);
                    e.Graphics.DrawLine(System.Drawing.Pens.White, e.CellBounds.Left, e.CellBounds.Top + 1, e.CellBounds.Right, e.CellBounds.Top + 1);

                    // right line...
                    e.Graphics.DrawLine(System.Drawing.Pens.DarkGray, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom);

                    // left line...
                    e.Graphics.DrawLine(System.Drawing.Pens.White, e.CellBounds.Left, e.CellBounds.Top, e.CellBounds.Left, e.CellBounds.Bottom);

                    //For rotation
                    double angle = (_rotationAngle / 180) * System.Math.PI;

                    double hSin = columnTextHeight * System.Math.Sin(angle);
                    double wCos = columnTextWidth * System.Math.Cos(angle);
                    double hCos = columnTextHeight * System.Math.Cos(angle);
                    double wSin = columnTextWidth * System.Math.Sin(angle);

                    double rotatedWidth  = hSin - wCos;
                    double rotatedHeight = hCos - wSin;

                    double dx = (e.CellBounds.Width + hSin - wCos) / 2;
                    double dy = (e.CellBounds.Height - hCos - wSin) / 2;

                    this.Columns[e.ColumnIndex].Width = ( int )System.Math.Abs(rotatedWidth) + 10;
                    int newColHeight = ( int )System.Math.Abs(rotatedHeight) + 10;
                    if (this.ColumnHeadersHeight < newColHeight)
                    {
                        this.ColumnHeadersHeight = newColHeight;
                    }

                    System.Drawing.Drawing2D.Matrix mx = new System.Drawing.Drawing2D.Matrix();
                    mx.Rotate(( float )_rotationAngle, System.Drawing.Drawing2D.MatrixOrder.Append);
                    float heightOffset = e.CellBounds.Y + 10;
                    mx.Translate(( float )(dx + e.CellBounds.X), heightOffset, System.Drawing.Drawing2D.MatrixOrder.Append);
                    e.Graphics.Transform = mx;

                    e.Graphics.DrawString(text, e.CellStyle.Font, System.Drawing.Brushes.Black, 0, 0, System.Drawing.StringFormat.GenericTypographic);

                    e.Graphics.ResetTransform();
                    e.Handled = true;
                }
                else
                {
                    base.OnCellPainting(e);
                }
            }
Ejemplo n.º 7
0
        public static bool GradientHeaders(StringAlignment stringAlignment,
                                           System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
        {
            SolidBrush   gridBrush;
            Pen          gridLinePen;
            StringFormat sf = new StringFormat();
            SolidBrush   fillBrush;
            Color        c1;
            Color        c2;

            c1 = Color.Black;
            //c2 = Color.FromArgb(43, 44, 1);
            c2 = Color.DimGray;

            fillBrush   = new SolidBrush(Color.LightGray);
            gridBrush   = new SolidBrush(Color.Black);
            gridLinePen = new Pen(gridBrush);

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Center;

            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(e.CellBounds,
                                                                                c1,
                                                                                c2,
                                                                                LinearGradientMode.Vertical);

            e.Graphics.FillRectangle(myLinearGradientBrush, e.CellBounds);


            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                                e.CellBounds.Top, e.CellBounds.Right - 1,
                                e.CellBounds.Bottom);


            if (e.CellBounds.Left == 0)
            {
                e.Graphics.DrawLine(gridLinePen,
                                    e.CellBounds.Left,
                                    e.CellBounds.Top,
                                    e.CellBounds.Left,
                                    e.CellBounds.Bottom);
            }

            e.Graphics.DrawLine(gridLinePen,
                                e.CellBounds.Left,
                                e.CellBounds.Bottom - 1,
                                e.CellBounds.Right - 1,
                                e.CellBounds.Bottom - 1);


            e.Graphics.DrawLine(gridLinePen,
                                e.CellBounds.Left,
                                e.CellBounds.Top,
                                e.CellBounds.Right - 1,
                                e.CellBounds.Top);


            //Draw the text content of the cell, ignoring alignment.
            if (e.Value != null)
            {
                e.Graphics.DrawString(e.Value.ToString(),
                                      e.CellStyle.Font,
                                      fillBrush,
                                      e.CellBounds,
                                      sf);
            }

            e.Handled = true;



            fillBrush.Dispose();
            gridLinePen.Dispose();
            gridBrush.Dispose();
            myLinearGradientBrush.Dispose();


            return(true);
        }