Csharp/C Sharp/2D Graphics/SolidBrush
new SolidBrush(ForeColor)
<source lang="csharp"> using System; using System.Drawing; using System.Windows.Forms;
class HelloCenteredMeasured: Form {
public static void Main() { Application.Run(new HelloCenteredMeasured()); } public HelloCenteredMeasured() { Text = "Hello Centered Using MeasureString"; BackColor = SystemColors.Window; ForeColor = SystemColors.WindowText; ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs pea) { Graphics graphics = pea.Graphics; string str = "Hello, world!"; SizeF sizefText = graphics.MeasureString(str, Font); graphics.DrawString(str, Font, new SolidBrush(ForeColor), (ClientSize.Width - sizefText.Width) / 2, (ClientSize.Height - sizefText.Height) / 2); }
}
</source>
Solid Brush: Firebrick
<source lang="csharp"> using System; using System.Collections.Generic; using System.ruponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; public class MainForm : Form {
public static void Main() { Application.Run(new MainForm()); } protected void OnPaint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; SolidBrush blueBrush = new SolidBrush(Color.Blue); SolidBrush pen2 = (SolidBrush)Brushes.Firebrick; g.FillEllipse(blueBrush, 10, 10, 100, 100); g.FillPie(Brushes.Black, 150, 10, 120, 150, 90, 80); SolidBrush brush3 = new SolidBrush(Color.Purple); g.FillPolygon(brush3, new Point[]{ new Point(30, 140), new Point(265, 200), new Point(100, 225), new Point(190, 190), new Point(50, 330), new Point(20, 180)}); Rectangle r = new Rectangle(150, 10, 130, 60); g.FillRectangle(Brushes.Blue, r); g.DrawString("Hello out there...How are ya?", new Font("Arial", 12), Brushes.White, r); }
}
</source>