首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

VS2010 DataGridView 灰色背景去除/自定義

     編輯:程式設計綜合問答

現象

DataGridView 行數不足時,底部空白區域顯示灰色背景(ControlDark),影響美觀。

解決方案

  1. 設置 BackgroundColor 為透明或所需顏色(屬性面板或代碼):
    dataGridView1.BackgroundColor = Color.White; // 或 Color.Transparent
  2. 若需完全自定義繪製,處理 RowPostPaint/CellPainting 事件。
  3. WPF DataGrid 不同屬性:Background="Transparent" 或 RowBackground/AlternatingRowBackground。

MSDN 官方樣式教程

DataGridView 控件樣式完整指南 —— 涵蓋列標題、行、單元格、選中、邊框、網格線等所有可視屬性。

常見坑

  • EnableHeadersVisualStyles = false 後才能自定義表頭樣式。
  • 虛擬模式 (VirtualMode) 下背景色需在 CellValueNeeded 同步設置。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved