protected override void OnPaintForeground(PaintEventArgs e) { if (displayHeader) { // jmarshall // using (SolidBrush b = new SolidBrush(GetStyleColor())) // e.Graphics.FillRectangle(b, 0, 0, Width, BORDER_WIDTH); // jmarshall end // Assuming padding 20px on left/right; 20px from top; max 40px height Rectangle bounds = new Rectangle(20, 20, ClientRectangle.Width - 2 * 20, 40); TextRenderer.DrawText(e.Graphics, Text, GetThemeFont("Form.Title"), bounds, EffectiveForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); } MetroBorderStyle bs = BorderStyle; if (bs == MetroBorderStyle.Default && !TryGetThemeProperty("BorderStyle", out bs)) { bs = MetroBorderStyle.None; } if (bs == MetroBorderStyle.FixedSingle) { using (Pen pen = new Pen(GetThemeColor("BorderColor"))) // TODO: Use style color for active window? { e.Graphics.DrawLines(pen, new[] { new Point(0, BORDER_WIDTH), new Point(0, Height - 1), new Point(Width - 1, Height - 1), new Point(Width - 1, BORDER_WIDTH) }); } } if (Resizable && (SizeGripStyle == SizeGripStyle.Auto || SizeGripStyle == SizeGripStyle.Show)) { using (SolidBrush b = new SolidBrush(GetThemeColor("Button.ForeColor.Disabled"))) { Size resizeHandleSize = new Size(2, 2); e.Graphics.FillRectangles(b, new Rectangle[] { new Rectangle(new Point(ClientRectangle.Width - 14, ClientRectangle.Height - 6), resizeHandleSize), new Rectangle(new Point(ClientRectangle.Width - 10, ClientRectangle.Height - 6), resizeHandleSize), new Rectangle(new Point(ClientRectangle.Width - 10, ClientRectangle.Height - 10), resizeHandleSize), new Rectangle(new Point(ClientRectangle.Width - 6, ClientRectangle.Height - 6), resizeHandleSize), new Rectangle(new Point(ClientRectangle.Width - 6, ClientRectangle.Height - 10), resizeHandleSize), new Rectangle(new Point(ClientRectangle.Width - 6, ClientRectangle.Height - 14), resizeHandleSize) }); } } }
private void DrawBorder(Object sender, PaintEventArgs e) { MetroBorderStyle bs = BorderStyle; if (bs == MetroBorderStyle.Default && !TryGetThemeProperty("BorderStyle", out bs)) { return; } if (bs != MetroBorderStyle.FixedSingle) { return; } using (Pen pen = new Pen(GetThemeColor("BorderColor"))) e.Graphics.DrawRectangle(pen, 0, 0, Width - 1, Height - 1); }
/// <summary> /// Initializes a new instance of the <see cref="MetroForm"/> class. /// </summary> public MetroForm() { // Init default field's value _backgroundColor = Color.White; _borderColor = Color.FromArgb(0xcc, 0xcc, 0xcc); _borderWidth = BORDER_WIDTH; _formFont = new Font("Segoe UI Light", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 0); _formIconPosition = new Point(_borderWidth + 5, _borderWidth + 5); _formCaptionPosition = new PointF(_formIconPosition.X + Icon.Size.Width + 5, _formIconPosition.Y + 6f); _borderStyle = MetroBorderStyle.Sizable; // Set serveral option for paint SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | // <-- prevents size handle artifacts ControlStyles.UserPaint, true); FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.CenterScreen; }