protected override void OnPaint(PaintEventArgs pevent) { var back = GetEffectiveColor(); var fore = (back.R > 128 && back.G > 128 && back.B > 128) ? ForeColor : Color.White; //var fore = ( ? ForeColor, ColorForm) pevent.Graphics.Clear(back); if (Image == null) { TextRenderer.DrawText(pevent.Graphics, Text, Font, ClientRectangle, fore, back, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); } if (Image != null) { pevent.Graphics.DrawImage(Image, (Width - Image.Width) / 2, (Height - Image.Height) / 2, Image.Width, Image.Height); } //using (var b = new SolidBrush(Color.FromArgb(255 - back.R, 255 - back.G, 255 - back.B))) //{ // var p = new PointF(); // p.Y = (float)(Height - Font.Height)/2; // pevent.Graphics.DrawString(Text, Font, b, p); //} }
public override Size GetPreferredSize(Size proposedSize) { using (var g = CreateGraphics()) { proposedSize = new Size(int.MaxValue, int.MaxValue); return(TextRenderer.MeasureText(g, Text, _font, proposedSize, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis)); } }
private void DrawTextPrompt(Graphics g) { Rectangle clientRectangle = ClientRectangle; clientRectangle.Offset(TextAlign == HorizontalAlignment.Left ? 1 : 0, 1); TextRenderer.DrawText(g, promptText, Font, clientRectangle, SystemColors.GrayText, BackColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.NoPadding | TextFormatFlags.EndEllipsis); }
protected override void OnPaintForeground(PaintEventArgs e) { if (Highlight && MetroControlState == "Normal") { using (Pen p = new Pen(GetStyleColor())) { Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1); e.Graphics.DrawRectangle(p, borderRect); borderRect = new Rectangle(1, 1, Width - 3, Height - 3); e.Graphics.DrawRectangle(p, borderRect); } } else { using (Pen p = new Pen(GetThemeColor("BorderColor"))) { Rectangle borderRect = new Rectangle(0, 0, Width - 1, Height - 1); e.Graphics.DrawRectangle(p, borderRect); } } TextRenderer.DrawText(e.Graphics, Text, EffectiveFont, ClientRectangle, EffectiveForeColor, EffectiveBackColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
protected override void OnPaintForeground(PaintEventArgs e) { using (Pen p = new Pen(GetThemeColor("BorderColor"))) { int width = ClientRectangle.Width - (DisplayStatus ? 31 : 1); Rectangle boxRect = new Rectangle((DisplayStatus ? 30 : 0), 0, width, ClientRectangle.Height - 1); e.Graphics.DrawRectangle(p, boxRect); } Color fillColor = Checked ? GetStyleColor() : GetThemeColor("CheckBox.BorderColor.Normal"); using (SolidBrush b = new SolidBrush(fillColor)) { int width = ClientRectangle.Width - (DisplayStatus ? 34 : 4); Rectangle boxRect = new Rectangle(DisplayStatus ? 32 : 2, 2, width, ClientRectangle.Height - 4); e.Graphics.FillRectangle(b, boxRect); } using (SolidBrush b = new SolidBrush(EffectiveBackColor)) // TODO: ???? { int left = Checked ? Width - 11 : (DisplayStatus ? 30 : 0); Rectangle boxRect = new Rectangle(left, 0, 11, ClientRectangle.Height); e.Graphics.FillRectangle(b, boxRect); } using (SolidBrush b = new SolidBrush(GetThemeColor("CheckBox.BorderColor.Hover"))) { int left = Checked ? Width - 10 : (DisplayStatus ? 30 : 0); Rectangle boxRect = new Rectangle(left, 0, 10, ClientRectangle.Height); e.Graphics.FillRectangle(b, boxRect); } if (DisplayStatus) { Rectangle textRect = new Rectangle(0, 0, 30, ClientRectangle.Height); TextRenderer.DrawText(e.Graphics, Text, EffectiveFont, textRect, EffectiveForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); } }
// Override to make the current style color the effective background color //public override Color EffectiveBackColor { get { return ShouldSerializeBackColor() ? base.EffectiveBackColor : GetStyleColor(); } } protected override void OnPaintForeground(PaintEventArgs e) { Color foreColor = EffectiveForeColor; Color tileColor = GetStyleColor(); Rectangle buttonRect = DisplayRectangle; using (SolidBrush b = new SolidBrush(tileColor)) { e.Graphics.FillRectangle(b, buttonRect); } if (UseTileImage && TileImage != null) { e.Graphics.DrawImage(TileImage, buttonRect, TileImageAlign); } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; if (PaintTileCount && TileCount > 0) { e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; TextRenderer.DrawText(e.Graphics, TileCount.ToString(), GetThemeFont("Tile.Count"), buttonRect, foreColor, tileColor, TextFormatFlags.Right | TextFormatFlags.Top); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault; } TextRenderer.DrawText(e.Graphics, Text, EffectiveFont, buttonRect, foreColor, tileColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.LeftAndRightPadding | TextFormatFlags.EndEllipsis); }
protected override void OnPaintForeground(PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.HighQuality; using (Pen p = new Pen(GetThemeColor("BorderColor"))) { Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); e.Graphics.DrawEllipse(p, boxRect); } if (Checked) { using (SolidBrush b = new SolidBrush(GetStyleColor())) { Rectangle boxRect = new Rectangle(3, Height / 2 - 3, 6, 6); e.Graphics.FillEllipse(b, boxRect); } } e.Graphics.SmoothingMode = SmoothingMode.Default; Rectangle textRect = new Rectangle(16, 0, Width - 16, Height); TextRenderer.DrawText(e.Graphics, Text, EffectiveFont, textRect, EffectiveForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.FillRectangle(_backSolidBrush, 0, 0, Width, Height); TextRenderer.DrawText(e.Graphics, Text, _font, new Rectangle(0, 0, Width, Height), Theme.LinkLabelForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
protected override void OnPaintForeground(PaintEventArgs e) { TextRenderer.DrawText(e.Graphics, Text, EffectiveFont, ClientRectangle, EffectiveForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
protected override void OnPaintForeground(PaintEventArgs e) { using (Pen p = new Pen(GetThemeColor("BorderColor"))) { Rectangle boxRect = new Rectangle(0, Height / 2 - 6, 12, 12); e.Graphics.DrawRectangle(p, boxRect); } if (Checked) { Color fillColor = CheckState == CheckState.Indeterminate ? GetThemeColor("BorderColor") : GetStyleColor(); using (SolidBrush b = new SolidBrush(fillColor)) { Rectangle boxRect = new Rectangle(2, Height / 2 - 4, 9, 9); e.Graphics.FillRectangle(b, boxRect); } } Rectangle textRect = new Rectangle(16, 0, Width - 16, Height); TextRenderer.DrawText(e.Graphics, Text, EffectiveFont, textRect, EffectiveForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
private void DrawProgressText(Graphics graphics) { if (HideProgressText) { return; } TextRenderer.DrawText(graphics, ProgressPercentText, EffectiveFont, ClientRectangle, EffectiveForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
//private Size MeasureText(string text) //{ // Size preferredSize; // using (Graphics g = CreateGraphics()) // { // Size proposedSize = new Size(int.MaxValue, int.MaxValue); // preferredSize = TextRenderer.MeasureText(g, text, MetroFonts.TabControl(metroLabelSize, metroLabelWeight), proposedSize, // TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis | TextFormatFlags.NoPadding); // } // return preferredSize; //} private void DrawTab(int index, Graphics graphics) { TabPage tabPage = TabPages[index]; Rectangle tabRect = GetTabRect(index); if (index == 0) { tabRect.X = DisplayRectangle.X; } //Rectangle bgRect = tabRect; tabRect.Width += 20; // TODO: Why??? //using (Brush bgBrush = new SolidBrush(backColor)) //{ // graphics.FillRectangle(bgBrush, bgRect); //} TextRenderer.DrawText(graphics, tabPage.Text, EffectiveFont, tabRect, EffectiveForeColor, EffectiveBackColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }
protected override void OnPaintForeground(PaintEventArgs e) { using (SolidBrush b = new SolidBrush(GetStyleColor())) e.Graphics.FillRectangle(b, 0, 0, Width, BORDER_WIDTH); if (displayHeader) { // 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) }); } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.FillRectangle(Enabled ? _backgroundBrush : _disabledBrush, 0, 0, Size.Width, Size.Height); var penToUse = _borderPen; if (Highlight) { penToUse = _buttonHighlightPen; } else if (_clicking) { penToUse = _buttonClickPen; } else if (_hovering) { penToUse = _borderHoverPen; } e.Graphics.DrawRectangle(penToUse, 0, 0, Size.Width - 1, Size.Height - 1); TextRenderer.DrawText(e.Graphics, Text, _font, new Rectangle(0, 0, Width, Height), Theme.ButtonForeColor, TextAlign.AsTextFormatFlags() | TextFormatFlags.EndEllipsis); }