【发布时间】:2015-06-15 19:53:24
【问题描述】:
我正在 PDFsharp 中填充表格以显示图表图例数据。我的列表中有 14 个对象,仅显示 2 个,并且它们的矩形颜色相同。它们每个都有独特的颜色可供使用。如何让它们全部正确显示?
//Draw the table Row Borders
xGrap.DrawRectangle(XPens.DarkSeaGreen, XBrushes.DarkSeaGreen, snoColumn); //Use different Color for Colum
xGrap.DrawRectangle(XPens.DarkSeaGreen, XBrushes.DarkSeaGreen, snoStudentName);
//Writting Table Header Text
textformater.DrawString(" Color", tableheader, XBrushes.Black, snoColumn);
textformater.DrawString(" Subdivision Name", tableheader, XBrushes.Black, snoStudentName);
foreach (var item in data)
{
string colorStr = item.Color;
Regex regex = new Regex(@"rgb\((?<r>\d{1,3}),(?<g>\d{1,3}),(?<b>\d{1,3})\)");
Match match = regex.Match(colorStr);
if (match.Success)
{
int r = int.Parse(match.Groups["r"].Value);
int g = int.Parse(match.Groups["g"].Value);
int b = int.Parse(match.Groups["b"].Value);
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(r, g, b));
xGrap.DrawRectangle(brush, snoColumnVal);
textformater.DrawString(item.Name, bodyfont, XBrushes.Black, snoStudentNameVal);
};
};
对象列表
这是我目前得到的结果
【问题讨论】:
-
第一行似乎是 Data[0],但第二行不是 Data[1]。你有完整的项目,你可以在调试器中单步执行它,你可以看到你为 r,g,b 得到了哪些值,以及 foreach 循环做了多少次迭代。