把QTP Report中的运行结果状态根据结果显示为不同的颜色:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex < 0) return; if (e.ColumnIndex == dataGridView1.Columns["CaseStatus"].Index) { if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Passed") { e.CellStyle.ForeColor = Color.Green; } else if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Failed") { e.CellStyle.ForeColor = Color.Red; } else if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "Warning") { e.CellStyle.ForeColor = Color.Goldenrod; } else if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "No Run") { e.CellStyle.ForeColor = Color.Gray; } } }