設定資料清單控制項隔行變色
只需兩句代碼即可搞定,非常舒服。
dataGridViewX1.RowsDefaultCellStyle.BackColor = Color.FromArgb(237, 243, 254);
dataGridViewX1.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(199, 237, 204);
滑鼠經過改變形狀及行變色
參照:http://www.cnblogs.com/greatverve/archive/2012/08/09/DataGridView-MouseEnter-MouseLeave.html
首先添加CellMouseEnter()與CellMouseLeave()事件。
/// <summary>/// 用來記錄先前的顏色值/// </summary>Color colorTmp = Color.White;/// <summary>/// 記錄滑鼠形狀/// </summary>Cursor cursorTmp = Cursor.Current;private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e){ if (e.RowIndex >= 0) { colorTmp = dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor; dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Silver; if (e.ColumnIndex == 1)//改變第二列滑鼠形狀 { cursorTmp = this.Cursor; this.Cursor = Cursors.Hand; } }}private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e){ if (e.RowIndex >= 0) { dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = colorTmp; if (e.ColumnIndex == 1) { this.Cursor = cursorTmp; } }}