new SolidBrush(ForeColor) : SolidBrush « 2D Graphics « C# / C Sharp






new SolidBrush(ForeColor)

 
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);
     }
}

 








Related examples in the same category

1.Solid Brush: FirebrickSolid Brush: Firebrick