Exemplo n.º 1
0
        private void dgvTrainView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
                        //是否是选中状态
            if ((e.State & DataGridViewElementStates.Selected) ==
                        DataGridViewElementStates.Selected)
            {
                // 计算选中区域Size
                int width = dgvTrainView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible);// +dgvTrainView.Width - 2;

                Rectangle rowBounds = new Rectangle(
                  0, e.RowBounds.Top, width,
                    e.RowBounds.Height - 1);

                // 绘制选中背景色
                using (LinearGradientBrush backbrush =
                    new LinearGradientBrush(rowBounds,
                        Color.Wheat,
                        Color.BurlyWood, 90.0f))
                {
                    e.Graphics.FillRectangle(backbrush, rowBounds);
                    e.PaintCellsContent(rowBounds);
                    e.Handled = true;
                }

            }
        }