$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
Editors Control for Windows Forms
Powerful data input control for WinForms application, flexible data entry controls, strict validation
Home > WinForms UI Controls > User Manual > Add Buttons in C# in C#

Add Buttons to Text Box in C#

The Text Box Control for Windows Forms is not only an alternative skin control to the standard Windows Forms text box control, but also provides various enhanced properties to store prompt information if no entry available. The Text Box allows users to add a text box to their Windows Forms applications with the same look and feel of other Windows Forms controls. With the text box, users can input text in a single line or multiple lines.
The Text Box Control for WinForms provides great flexibility for customizing the element structure of a control. The following tutorial will show how to add buttons in C# to the Text Box control.

Add Buttons to Text Box in C#

Here, we are going to build 3 buttons that will be added to the StackLayoutPanel element to arrange them in stacked formation. In addition, we are going to configure the Padding to the buttons to increase their size and the margin to leave some space between the buttons.

KetticButtonElement button = new KetticButtonElement();
button1.Click += new EventHandler(button_Click);
button1.Padding = new Padding(3, 1, 3, -3);
button1.Margin = new Padding(1, 1, 1, 1);
button1.Text = "Button1 Text";

KetticButtonElement button2 = new KetticButtonElement();
button2.Click += new EventHandler(button_Click);
button2.Padding = new Padding(3, 1, 3, -3);
button2.Margin = new Padding(2, 2, 3, 2);
button2.Text = "Button2 Text";

KetticButtonElement button3 = new KetticButtonElement();
button3.Click += new EventHandler(button_Click);
button3.Padding = new Padding(4, 2, 4, -4);
button3.Margin = new Padding(3, 1, 3, 1);
button3.Text = "Button3 Text";

StackLayoutElement stackPanel = new StackLayoutElement();
stackPanel.Direction = Direction.Horizontal;
stackPanel.Margin = new Padding(1, 0, 1, 0);
stackPanel.Child.Add(button);
stackPanel.Child.Add(button2);
stackPanel.Child.Add(button3);
Then, we need to put the stack layout panel into Kettic text box and place the item which determines the text box and the stack layout panel in dock layout panel to configure the proper layout between the text box of Kettic Text Box and the buttons.

KetticTextBoxItem tbItem = this. ketticTextBox1.TextBoxElement.TextBoxItem;
this.ketticTextBox1.TextBoxElement.Child.Remove(tbItem);

DockLayoutPanel dockPanel = new DockLayoutPanel();
dockPanel.Child.Add(stackPanel);
dockPanel.Child.Add(tbItem);
DockLayoutPanel.SetDock(tbItem, Kettic.WinForms.Layouts.Dock.Left);
DockLayoutPanel.SetDock(stackPanel, Kettic.WinForms.Layouts.Dock.Right);
this.ketticTextBox1.TextBoxElement.Child.Add(dockPanel);
Now, it is the time to adjust the properties, Margin and Padding, to set the elements of Kettic Text Box to add space between the button and the text.

this.ketticTextBox1.TextBoxElement.Padding = new Padding(2, 2, 2, 2);
tbItem.Margin = new Padding(1, 2, 1, 1);
Implement the event handler to complete the Click event scenario.

void button_Click(object sender, EventArgs e)
{
ketticButtonElement button = sender as KetticButtonElement;
ketticMessageBox.Display("Clicked! " + button.Text);
}
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls