我是C#
的新用戶並使用Windows Forms
。
如屏幕截圖所示,有沒有人知道我點擊取消按鈕時如何在DataGridView
中選定的行水平交叉(交叉線)?
我在網上搜索,但我沒有得到解決方案。
private void ButtonCancel_Click(object sender, EventArgs e)
{
}
我是C#
的新用戶並使用Windows Forms
。
如屏幕截圖所示,有沒有人知道我點擊取消按鈕時如何在DataGridView
中選定的行水平交叉(交叉線)?
我在網上搜索,但我沒有得到解決方案。
private void ButtonCancel_Click(object sender, EventArgs e)
{
}
可以使用RowPostPaint事件:
void dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) {
if (e.RowIndex == 1) {
Rectangle r = e.RowBounds;
e.Graphics.DrawLine(Pens.DarkRed, r.Left,
r.Top + (r.Height/2),
r.Left + r.Width,
r.Top + (r.Height/2));
}
}
與您要用於繪畫的行索引替換索引1。
你可以改變每個單元的排在後面的顏色這有可能有同樣的效果
var row = dataGridView.Rows[rowIndex];
foreach(DataGridViewCell cell in row.Cells)
{
cell.Style.BackColor = Color.Red;
}
您需要利用使用GDI +的'DataGridView'行。看看[這個示例](http://www.codeproject.com/Articles/8620/Drawing-and-Editing-Lines-with-GDI) - 雖然它很古老。在「DataGridView」上繪製線條之前,您只需確定線條的起點和終點。 – kennyzx