예제 #1
0
파일: Engine.cs 프로젝트: radtek/Gradual
        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;
            }
        }
예제 #2
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);
        }