وسط چین کردن عنوان فرم

برای وسط چین کردن عنوان فرم در سی شارپ، در رویداد Load فرم کدهای زیر را بنویسید :

private void Form1_Load(object sender, System.EventArgs e)
{
    Graphics graphics = this.CreateGraphics();
    double startingPoint = (this.Width / 2) - (graphics.MeasureString(this.Text.Trim(), this.Font).Width / 2);
    double widthOfASpace = graphics.MeasureString(" ", this.Font).Width;
    string temp = " ";
    double tempWidth = 0;
    while ((tempWidth + widthOfASpace) < startingPoint)
    {
        temp += " ";
        tempWidth += widthOfASpace;
    }
    this.Text = temp + this.Text.Trim();
}