Question

Is there a way to center-align the text in a WinForms form? Also known as the title bar caption or title bar text? So far the only way I can see to do it is pad the string with spaces. I am setting the title bar caption using the Form.Text property.

I should add that I am using a 3rd party ribbon form, so the app looks like a Microsoft Office 2007 application. And those apps center-align the text, presumably because when the text is left-aligned it gets added to the jumble of buttons on the top left and looks bad.

Was it helpful?

Solution 2

For anyone who is interested, I am using Syncfusion Essential Tools. The solution is this:

this.ribbonToolbar.TitleAlignment = Syncfusion.Windows.Forms.Tools.TextAlignment.Center;

The title alignment is a property of the ribbon toolbar and not of the RibbonForm, which explains why I didn't find it before. Thanks to all who responded.

OTHER TIPS

Honestly - don't. Windows users expect certain things to work in a certain way, and this would not meet standard practices. Not to mention that the button in the taskbar would then no longer show the titlebar text as it would be pushed to the right.

You can take over the non-client area of a form completely, in which case you can do what you like. Even if you did this, though, my recommendation for your design would be to have the title at the top left, close button at the top right, etc.

The title bar is rendered by the system and there is no option for centering the text.

In order to effectively center, you'd need to draw the title bar yourself - this can be done in native code by handling WM_NCPAINT messages and such but not sure how this can easily be done in .NET.

But why do you want to change? Windows UX standards have the text left aligned.

I don't believe you can.

You could hide the title bar, and replace it with a user control and implement the same functionality a title bar has, but I don't think that would be a good idea.

Consistency for the user is probably more important than whatever reason you have for wanting to center the text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top