I used this structure to demonstrate:
struct RowItem { public int R, G, B; public string Text; }
Here are my test data:
var data = new[] { new RowItem{R = 255, G = 0, B = 0, Text = "Red row"}, new RowItem{R = 0, G = 255, B = 0, Text = "Green row"}, new RowItem{R = 255, G = 255, B = 0, Text = "Yellow row"}, new RowItem{R = 0, G = 0, B = 255, Text = "Blue row"}, new RowItem{R = 255, G = 0, B = 255, Text = "Purple row"}, new RowItem{R = 0, G = 255, B = 255, Text = "Cyan row"}, new RowItem{R = 0, G = 0, B = 0, Text = "Black row"} };
And here is the code that makes the drawing:
foreach (var item in data) { y = y + 30; XRect snoColumnVal = new XRect(35, y, 60, 25); XRect snoStudentNameVal = new XRect(100, y, 250, 25); var brush = new XSolidBrush(XColor.FromArgb(255, item.R, item.G, item.B)); gfx.DrawRectangle(XPens.Black, brush, snoColumnVal); textformater.DrawString(item.Text, font, XBrushes.Black, snoStudentNameVal); }
R, G and B are color components (range from 0 to 255).