public void DrawBox(Graphics g, Font font, Rectangle bounds, string text, bool drawBackground, BorderInfo borders, TextAlignment textAlignment) { DrawBox(g, font, bounds, text, drawBackground, borders, textAlignment, false); }
public void DrawBox(Graphics g, Font font, Rectangle bounds, string text, bool drawBackground, BorderInfo borders, TextAlignment textAlignment, bool bold, Brush backgroundColorOverride) { //draw the background if (drawBackground) { if (backgroundColorOverride != null) { g.FillRectangle(backgroundColorOverride, bounds); } else { visualStyleRenderer.DrawBackground(g, bounds); } } //draw the borders if (borders != null) { //handle overlaps of the border - BorderInfo.OverlapLeftRightBottom if (borders.All && borders.OverlapBottomRight) { //calculate border, paint with overlap g.DrawRectangle(borderPen, bounds); } } //draw the text if (!string.IsNullOrEmpty(text)) { //TODO: bold if (textAlignment == TextAlignment.Left) { visualStyleRenderer.DrawText(g, bounds, string.Format(" {0}", text), false, System.Windows.Forms.TextFormatFlags.Left | System.Windows.Forms.TextFormatFlags.EndEllipsis | System.Windows.Forms.TextFormatFlags.VerticalCenter); } else if (textAlignment == TextAlignment.Right) { visualStyleRenderer.DrawText(g, bounds, string.Format("{0} ", text), false, System.Windows.Forms.TextFormatFlags.Right | System.Windows.Forms.TextFormatFlags.EndEllipsis | System.Windows.Forms.TextFormatFlags.VerticalCenter); } else { visualStyleRenderer.DrawText(g, bounds, text, false, System.Windows.Forms.TextFormatFlags.HorizontalCenter | System.Windows.Forms.TextFormatFlags.EndEllipsis | System.Windows.Forms.TextFormatFlags.VerticalCenter); } } }
public void DrawBox(Graphics g, Font font, Rectangle bounds, string text, bool drawBackground, BorderInfo borders, TextAlignment textAlignment, bool bold, Brush backgroundOverride) { //draw the background if (drawBackground) { if (backgroundOverride != null) { g.FillRectangle(backgroundOverride, bounds); } else { //TODO: Turn off gradients if high contrast mode is enabled //draw gradient if 2 back colours if (backColour2 != Color.Empty) { using ( LinearGradientBrush linGrBrush = new LinearGradientBrush(bounds, backColour, backColour2, 270F)) { //just put a little of one colour in if (UsePartialBlend) { float[] factors = { 0.6f, 1.0f, 1.0f }; float[] positions = { 0.0f, 0.5f, 1.0f }; Blend blend = new Blend(); blend.Factors = factors; blend.Positions = positions; linGrBrush.Blend = blend; } else if (NoGradientBlend) { float[] factors = { 0.6f, 0.6f, 0.6f }; float[] positions = { 0.0f, 0.5f, 1.0f }; Blend blend = new Blend(); blend.Factors = factors; blend.Positions = positions; linGrBrush.Blend = blend; } g.FillRectangle(linGrBrush, bounds); } } else { //else draw plain g.FillRectangle(backColourBrush, bounds); } } } //draw the borders if (borders != null) { //handle overlaps of the border - BorderInfo.OverlapLeftRightBottom if (borders.All && borders.OverlapBottomRight) { //calculate border, paint with overlap g.DrawRectangle(borderPen, bounds); } } //draw the text if (!string.IsNullOrEmpty(text)) { if (bold) { Font boldFont = new Font(font, FontStyle.Bold); if (textAlignment == TextAlignment.Left) { g.DrawString(text, boldFont, foreColourBrush, bounds, StringFormats.Left); } else if (textAlignment == TextAlignment.Right) { g.DrawString(text, boldFont, foreColourBrush, bounds, StringFormats.Right); } else { g.DrawString(text, boldFont, foreColourBrush, bounds, StringFormats.Center); } } else { if (textAlignment == TextAlignment.Left) { g.DrawString(text, font, foreColourBrush, bounds, StringFormats.Left); } else if (textAlignment == TextAlignment.Right) { g.DrawString(text, font, foreColourBrush, bounds, StringFormats.Right); } else { g.DrawString(text, font, foreColourBrush, bounds, StringFormats.Center); } } } }