2011-06-20 22 views

回答

2

您鏈接到第二個例子是正是你所需要的人。網格內的每一行都將觸發DataGridView.RowPrePaint事件。

此事件的文檔頁面上的示例僅自定義呈現選定的行,因爲它包含以下檢查。

// Determine whether the cell should be painted 
// with the custom selection background. 
if ((e.State & DataGridViewElementStates.Selected) == 
      DataGridViewElementStates.Selected) 

刪除此檢查您將看到每行都有自定義背景。

+0

我刪除了那段代碼,但漸變色R不適用於行。我不知道爲什麼。它似乎默認風格重寫這種風格 – Arian

0

我不知道,如果這也幫助別人誰谷歌搜索後,土地在這裏,我根據這一些VB代碼,我在另一個論壇中發現:

using System; 
using System.Windows.Forms; 
using System.Drawing; 

namespace CPS 
{ 
    class gradientGrid : DataGridView 
    { 

     protected override void PaintBackground(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle gridBounds) 
     { 
      base.PaintBackground(graphics, clipBounds, gridBounds); 

      System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(clipBounds, Color.CadetBlue, Color.AntiqueWhite, System.Drawing.Drawing2D.LinearGradientMode.Horizontal); 
      graphics.FillRectangle(b, clipBounds); 
     } 
    } 
} 

一旦你建立了這個作爲一個單獨的類它顯示在你的(VS2010)工具箱,你把它在窗體上...

此代碼對整個數據網格視圖,以便做的每一行,你可以使用RowPrePaint事件.. 。

相關問題