110,537
社区成员
发帖
与我相关
我的任务
分享
void PaintText(Graphics g, Rectangle rect, string text, bool selected, DataGridViewCellStyle cell_style)
{
Document = parser.parse_text(text);
Point pt = rect.Location;
foreach (var node in Document.Nodes)
{
Font font = get_node_font(node, cell_style);
Color clr = get_node_color(node, selected, cell_style);
Size size = TextRenderer.MeasureText(node.InnerText, font);
pt.Y = rect.Top + (rect.Height - size.Height) / 2;
using (Brush bru = new SolidBrush(clr))
{
g.DrawString(node.InnerText, font, bru, pt);
}
pt.X += size.Width;
}
}
Font get_node_font(DOMNode node, DataGridViewCellStyle cell_style)
{
Font font = cell_style.Font;
if (node.Name == "font" && node.Attributes.ContainsKey("name") && node.Attributes.ContainsKey("size"))
{
float font_size = cell_style.Font.Size;
float.TryParse(node.Attributes["size"], out font_size);
font = new Font(node.Attributes["name"], font_size);
}
return font;
}
Color get_node_color(DOMNode node, bool selected, DataGridViewCellStyle cell_style)
{
Color clr = selected ? cell_style.SelectionForeColor : cell_style.ForeColor;
if (node.Name == "font" && node.Attributes.ContainsKey("color"))
{
clr = ColorTranslator.FromHtml(node.Attributes["color"]);
if (selected)
clr = Color.FromArgb(~(clr.ToArgb()&0x00FFFFFF));
}
return clr;
}