Loading...
Loading...
Guides implementation of the Syncfusion WinForms AutoLabel control for automatic label positioning with form controls. Use when users want to add labels that automatically reposition when controls move, create form layouts with paired label-control units, implement complex form designs with FlowLayout, or ensure labels stay synchronized with their associated controls. Covers labeling controls, positioning, spacing, size settings, theming, and events.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-autolabelInstall-Package Syncfusion.Tools.WindowsSyncfusion.Shared.Base.dllusing System;
using System.Windows.Forms;
using Syncfusion.Windows.Forms.Tools;
namespace AutoLabelDemo
{
public partial class Form1 : Form
{
private AutoLabel autoLabel1;
private TextBoxExt textBoxExt1;
public Form1()
{
InitializeComponent();
// Create a control to label (e.g., TextBox)
textBoxExt1 = new TextBoxExt();
textBoxExt1.Location = new System.Drawing.Point(150, 50);
textBoxExt1.Size = new System.Drawing.Size(200, 20);
// Create AutoLabel
autoLabel1 = new AutoLabel();
autoLabel1.Text = "Username:";
autoLabel1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular);
// Pair the label with the control
autoLabel1.LabeledControl = textBoxExt1;
autoLabel1.Position = AutoLabelPosition.Left;
autoLabel1.Gap = 10;
// Add to form
this.Controls.Add(textBoxExt1);
this.Controls.Add(autoLabel1);
}
}
}AutoLabelLabeledControlPositionGapLabeledControlPositionGap// Create form fields with left-aligned labels
AutoLabel nameLabel = new AutoLabel();
nameLabel.Text = "Name:";
nameLabel.LabeledControl = nameTextBox;
nameLabel.Position = AutoLabelPosition.Left;
nameLabel.Gap = 10;
AutoLabel emailLabel = new AutoLabel();
emailLabel.Text = "Email:";
emailLabel.LabeledControl = emailTextBox;
emailLabel.Position = AutoLabelPosition.Left;
emailLabel.Gap = 10;
this.Controls.Add(nameTextBox);
this.Controls.Add(nameLabel);
this.Controls.Add(emailTextBox);
this.Controls.Add(emailLabel);AutoLabel addressLabel = new AutoLabel();
addressLabel.Text = "Address:";
addressLabel.LabeledControl = addressTextBox;
addressLabel.Position = AutoLabelPosition.Top;
addressLabel.Gap = 5;
addressLabel.AutoSize = true;AutoLabel customLabel = new AutoLabel();
customLabel.Text = "Custom:";
customLabel.LabeledControl = myControl;
customLabel.Position = AutoLabelPosition.Custom;
customLabel.DX = -100; // 100 pixels to the left
customLabel.DY = 15; // 15 pixels down from control topusing Syncfusion.Windows.Forms;
// Apply Office 2016 theme to all labels
SkinManager.SetVisualStyle(label1, VisualTheme.Office2016Colorful);
SkinManager.SetVisualStyle(label2, VisualTheme.Office2016Colorful);
SkinManager.SetVisualStyle(label3, VisualTheme.Office2016Colorful);FlowLayoutPanel flowPanel = new FlowLayoutPanel();
flowPanel.FlowDirection = FlowDirection.TopDown;
flowPanel.Dock = DockStyle.Fill;
// FlowLayout treats AutoLabel + Control as one unit
flowPanel.Controls.Add(firstNameTextBox);
flowPanel.Controls.Add(firstNameLabel); // Paired with firstNameTextBox
flowPanel.Controls.Add(lastNameTextBox);
flowPanel.Controls.Add(lastNameLabel); // Paired with lastNameTextBox
// Labels automatically move with their controls
this.Controls.Add(flowPanel);| Property | Type | Default | Description |
|---|---|---|---|
| Control | null | The control that this label is paired with |
| AutoLabelPosition | Left | Relative position: Left, Top, Side, Custom |
| int | 0 | Horizontal and vertical gap between label and control |
| int | 0 | Horizontal distance from label left to control left |
| int | 0 | Vertical distance from label top to control top |
| bool | false | Automatically resize based on font size |
| string | "" | Label text content |
| ContentAlignment | TopLeft | Text alignment within label |
| Color | Control | Background color of the label |
| Color | ControlText | Text color of the label |
| Font | - | Font for the label text |
| Position | Behavior |
|---|---|
| Left | Label appears to the left of the control |
| Top | Label appears above the control |
| Side | Label appears on the side (right) of the control |
| Custom | Manual positioning using DX and DY or mouse drag |
| Event | Description |
|---|---|
| Fired when LabeledControl, Gap, or Position properties change |
LabeledControlGapLeftTopCustomAutoSize = trueSkinManager.SetVisualStyle(this.autoLabel1, VisualTheme.Office2016Colorful);LabeledControlGapDXDYPositionGapPosition