Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

How to set text to center of form tittle bar in C#.

Please help me.

Thanks and regards,
Kamlesh Nikam
Posted
Comments
syed shanu 29-Aug-14 4:45am    
Windows of WebForm

If its Winform chk this link :

Center Align the TExt of Form Title Bar.[^]

C#
private void Center_Text()
       {
           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();
       }
       private void Form2_Load(object sender, EventArgs e)
       {
           Center_Text();
       }
 
Share this answer
 
There is no "built in" way to do this: the standard is that form titles appear at the left next to the icon / system box and you shouldn't really change that - it goes against the normal UI guidelines.

You can do it if you want though: but it's not nice, or it's not simple: http://stackoverflow.com/questions/11947314/how-to-center-align-the-title-bar-text-in-windows-form[^]

Personally? I wouldn't.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900