private void DrawContent(Graphics gr, Rectangle bounds, Font font)
{
Rectangle innerBounds = new Rectangle(bounds.X + HeaderLeftMargin, bounds.Y,
bounds.Width - HeaderLeftMargin - HeaderRightMargin,
bounds.Height);
if (SortOrder != SortOrder.None)
innerBounds.Width -= (SortMarkSize.Width + SortOrderMarkMargin);
Size maxTextSize = TextRenderer.MeasureText(gr, Header, font, innerBounds.Size, TextFormatFlags.NoPadding);
Size textSize = TextRenderer.MeasureText(gr, Header, font, innerBounds.Size, _baseHeaderFlags);
if (SortOrder != SortOrder.None)
{
int tw = Math.Min(textSize.Width, innerBounds.Size.Width);
int x = 0;
if (TextAlign == HorizontalAlignment.Left)
x = innerBounds.X + tw + SortOrderMarkMargin;
else if (TextAlign == HorizontalAlignment.Right)
x = innerBounds.Right + SortOrderMarkMargin;
else
x = innerBounds.X + tw + (innerBounds.Width - tw) / 2 + SortOrderMarkMargin;
DrawSortMark(gr, bounds, x);
}
if (textSize.Width < maxTextSize.Width)
TextRenderer.DrawText(gr, Header, font, innerBounds, SystemColors.ControlText, _baseHeaderFlags | TextFormatFlags.Left);
else
TextRenderer.DrawText(gr, Header, font, innerBounds, SystemColors.ControlText, _headerFlags);
}