Loading...
Loading...
Guide developers to implement and customize the Syncfusion Windows Forms SfButton control for desktop applications. Use this when creating interactive buttons with text, images, styling, and theming in Windows Forms applications. Covers implementation, customization, and interaction handling.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-buttonusing Syncfusion.WinForms.Buttons;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Create and configure SfButton
SfButton sfButton1 = new SfButton();
sfButton1.Text = "Click Me";
sfButton1.Font = new System.Drawing.Font("Segoe UI", 10F);
sfButton1.Location = new System.Drawing.Point(50, 50);
sfButton1.Size = new System.Drawing.Size(120, 40);
// Add click event
sfButton1.Click += SfButton1_Click;
// Add to form
this.Controls.Add(sfButton1);
}
private void SfButton1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Button clicked!");
}
}sfButton1.Text = "Save";
sfButton1.Image = Image.FromFile(@"save-icon.png");
sfButton1.TextImageRelation = TextImageRelation.ImageBeforeText;
sfButton1.ImageSize = new Size(20, 20);sfButton1.Text = ""; // Empty text
sfButton1.Image = Image.FromFile(@"icon.png");
sfButton1.ImageSize = new Size(24, 24);
sfButton1.Style.BackColor = Color.White;
sfButton1.Style.Border = null;sfButton1.Style.BackColor = Color.LightBlue;
sfButton1.Style.ForeColor = Color.Black;
sfButton1.Style.HoverBackColor = Color.Blue;
sfButton1.Style.HoverForeColor = Color.White;
sfButton1.Style.PressedBackColor = Color.DarkBlue;
sfButton1.Style.PressedForeColor = Color.White;sfButton1.Text = "Variable Length Content";
sfButton1.AutoSize = true; // Auto-adjust to content
sfButton1.Font = new Font("Segoe UI", 11F);// In Program.cs Main():
SfSkinManager.LoadAssembly(typeof(Office2016Theme).Assembly);
// In form:
sfButton1.ThemeName = "Office2016Colorful";| Property | Type | Purpose |
|---|---|---|
| string | Button display text |
| Image | Button image/icon |
| Size | Dimensions of displayed image |
| TextImageRelation | Position of image relative to text |
| ContentAlignment | Text alignment within button |
| ContentAlignment | Image alignment within button |
| bool | Auto-fit button to content |
| bool | Enable text wrapping |
| bool | Show ellipsis for trimmed text |
| bool | Enable rich text formatting |
| Image | Background fill image |
| bool | Show focus indicator rectangle |
| string | Apply built-in theme |
| ButtonVisualStyle | Access appearance customization |
Syncfusion.Core.WinFormsSyncfusion.Shared.BaseSyncfusion.Office2016Theme.WinForms