Search code examples
c#.netwinformsbuttoncentering

Centering text on a button


I have created two buttons where the .Text property contains characters that I want to center, but I can't get it to work properly. Currently the buttons look like this:

enter image description here

And the code looks like this:

btnUp.Text = "▲";
btnDown.Text = "▼";
btnUp.TextAlign = ContentAlignment.MiddleCenter;
btnDown.TextAlign = ContentAlignment.MiddleCenter;

But what I really want is the Buttons' texts to be centered, so the arrows will be exactly in the middle of the controls. How would I achieve this?

A closer look to show why I am not happy:

enter image description here

Thanks to Thomas Mondel's solution Here is the result:

enter image description here


Solution

  • You can try to set the UseCompatibleTextRendering property on the buttons to True. It did the trick for me.

    UseCompatibleTextRendering

    Hope this helps.