| layout | post |
|---|---|
| title | Button Content in Windows Forms Button control | Syncfusion® |
| description | Button Content in SfButton supports rich text, text wrapping, ellipsis, content alignment, and automatic sizing. |
| platform | windowsforms |
| control | SfButton |
| documentation | ug |
The rich text can be displayed inside the WinForms Button by enabling the AllowRichText property and the proper rich text can be added in the Text property.
{% tabs %} {% highlight c# %} //Enable the rich text support this.sfButton1.AllowRichText = true
//Adding the rich text value. this.sfButton1.Text = "{\rtf1\ansi\deff0{\colortbl;\red0\green0\blue0;\red255\green0\blue0;}" + "{\fonttbl{\f0 Monotype Corsiva;\r\n}}\qc\f0\fs30 {\i Italic} {\b Bold} \cf2 Red}";
{% endhighlight %} {% endtabs %}
Note: When the AllowRichText property is false, even if you add the rich text to the Text property, it will draw as normal text inside the button.
The text can be wrapped in the WinForms Button by setting the AllowWrapText property to true.
{% tabs %} {% highlight c# %} //Initialize the text to SfButton sfButton1.Text = "SfButton with wrap text";
//Enable the text wrapping sfButton1.AllowWrapText = true;
{% endhighlight %} {% endtabs %}
Note: If the AutoSize property is enabled, the WinForms Button does not allow you to wrap the text.
The ellipsis character can be shown inside the WinForms Button by enabling the AllowEllipsis property.
{% tabs %} {% highlight c# %} //Enable AutoEllipsis property to show the ellipsis character. sfButton1.AutoEllipsis = true;
{% endhighlight %} {% endtabs %}
Note: The WinForms Button will trim the characters only when disabling the AutoSize property and text length should be greater than the button width.
The WinForms Button allows auto fitting the size based on the content by setting the AutoSize property to true.
{% tabs %} {% highlight c# %} //Auto fit the content of SfButton sfButton1.AutoSize = true; {% endhighlight %} {% endtabs %}
This section describes how to change the text and image alignment inside the WinForms Button.
The text alignment can be changed by initializing any one of the ContentAlignment enumeration value to the TextAlign property.
{% tabs %} {% highlight c# %} //Initialize the Top Center alignment to text. sfButton1.TextAlign = ContentAlignment.TopCenter;
{% endhighlight %} {% endtabs %}
The image alignment can be changed by initializing any one of the ContentAlignment enumeration value to the ImageAlign property.
{% tabs %} {% highlight c# %} //Initialize the Top Center alignment to Image. sfButton1.ImageAlign = ContentAlignment.TopCenter;
{% endhighlight %} {% endtabs %}


