Ankush

Ankush

  • NA
  • 267
  • 60.7k

Center Align the Text of Tile Bar of Mdi Parent Form

Feb 4 2016 10:00 AM
I have created a windows application in which there one of the form is Mdi Parent form. I want to center align the text of this form i.e. Mdi Parent form. I have the code to center align the text of title bar of form. It is working perfectly with Mdi Child forms but not with Mdi parent form. Create the method and just call the method in Form Load event.
 
private void UpdateTextPosition()
{
         Graphics g = this.CreateGraphics();
         Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
         Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
         String tmp = " ";
         Double tmpWidth = 0;
         while ((tmpWidth + widthOfASpace) < startingPoint)
         {
                  tmp += " ";
                  tmpWidth += widthOfASpace;
         }
         this.Text = tmp + this.Text.Trim();
}
 
 
If you debug the program with break point, you can see that the above method is working i.e. the work mentioned in method is done, but the problem is that the text of title bar is not visible. Just try to debug the code and you will know it. 
 
Please help !... Thanks in Advance.... 
 

Answers (1)