If cannot be perfect, by definition. You should not do it, because this is controlled by OS. For example, when I run my .NET applications on the version of Ubuntu I use right now, it centers the form titles, but it depends on desktop manager. If I used something like you do, the system would try to center a padded text, and it would look shifted right. And you don't know how next versions of Windows will look, and what skinning will be available. So,
never do such things.
Now, you still can fully customize the look of the title bar if you use directly opposite approach. But you cannot use a combined approach.
First, you can totally re-draw non-client area of your form, using raw (unmanaged) Windows API and non-client Windows messages. I would not recommend it either, as this is too much Windows specific. .NET tries to go out of Windows, and CLR is designed for platform compatibility. If you write your Forms applications accurately, you can run them on different OS without recompilation. With Windows-specific tricks, you will break this compatibility, and pretty likely, compatibility with future Microsoft systems.
Second approach is the most radical and the safest at the same time, it does not require any interop. You can show your form without any non-client areas at all. To do it, set the form property
System.Windows.Forms.FormFormBorderStyle
to
System.Windows.Forms.FormBorderStyle.None
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formborderstyle.aspx[
^],
http://msdn.microsoft.com/en-us/library/hw8kes41.aspx[
^].
When this is done, simply simulate all non-client controls (such as title bar) in the regular client area. Just create and add some custom controls simulating requires non-client form elements.
Now, a bonus advice: if some developers use such highly customized forms, they often make a step further to make the forms non-rectangular, but of some funky-looking shapes. This is easily done using the property
System.Windows.Forms.Control.Region
:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.region.aspx[
^].
—SA