2010-02-16 25 views
2

我有一個DataGridView我想繪製自定義字形(讓我們假設一個三角形)的列標題,當用戶點擊它。DataGridView自定義字形標題

我有財產EnableHeadersVisualStyles設置爲False

您是否有任何示例或建議如何達到預期結果?我是否需要從DataGridView或DataGridViewColumn繼承?

謝謝你在前進, 馬爾科

回答

0

你需要做的幾件事第一附加處理程序事件GridView_CellPainting的事件處理程序中做這樣的

void GridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 
     { 
       e.PaintBackground(e.ClipBounds, true); 
       StringFormat sf = new StringFormat(); 
       sf.Alignment = StringAlignment.Near; 
       e.Graphics.DrawString(e.FormattedValue.ToString() this.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(this.ColumnHeadersDefaultCellStyle.ForeColor),e.CellBounds, sf); 

          // 
          //Place code to draw your custom gliph 
          // 
       e.Handled = true; 
      } 
     } 

行「sf.Alignment = StringAlignment.Near;」設置文本被塗左左alignemet,如果你需要它,否則改變

0

我發現這有幫助。它可以很好地工作

如果您希望列標題完美居中,您需要 禁用排序。將該列的SortMode屬性設置爲 「NonSortable」。這應防止在列文本居中或右對齊時爲 排序字形保留空間。

來自:How can I center the heading in a column on a DataGridView?