Windows Forms Controls

Windows Forms (WinForms) is a free, open-source client development platform for creating rich desktop applications for Windows. It provides a rich set of UI controls that allow you to build sophisticated user interfaces.

Common Controls

Buttons

The Button control is fundamental for user interaction, allowing users to trigger actions. You can customize its appearance, text, and associated events.

Example: Adding a Button

To add a button to your form:


// In your form's constructor or Load event
Button myButton = new Button();
myButton.Text = "Click Me";
myButton.Location = new System.Drawing.Point(50, 50);
myButton.Click += new EventHandler(MyButton_Click); // Event handler
this.Controls.Add(myButton);

// Event handler method
private void MyButton_Click(object sender, EventArgs e)
{
    MessageBox.Show("Button clicked!");
}
            

Text Boxes

The TextBox control is used for displaying and editing plain text. It supports multiline input, password masking, and various formatting options.

Example: Getting Text from a TextBox

Retrieve the text entered by the user:


string userInput = textBox1.Text;
// Perform operations with userInput
            

Labels

Label controls are used to display static text, such as titles, descriptions, or prompts for other controls.

Checkboxes and Radio Buttons

CheckBox controls allow users to select or deselect an option. RadioButton controls are used when you want to present a list of mutually exclusive choices.

List Boxes and Combo Boxes

ListBox displays a list of items from which the user can select one or more. ComboBox combines a text box with a drop-down list, offering a space-saving alternative.

Grids (DataGridView)

The DataGridView control is a powerful component for displaying tabular data. It supports sorting, editing, and various customization options for columns and rows.

Layout and Container Controls

Panels

Panel controls act as containers for grouping other controls, helping to organize your form's layout and manage visual styles.

GroupBoxes

GroupBox controls visually group related controls by drawing a border and an optional title around them. This is often used for logical grouping, similar to radio button groups.

Tab Controls

The TabControl allows you to create multi-page interfaces where each page can contain its own set of controls. Users navigate between pages using tabs.

Navigation Controls

Menus

MenuStrip provides a standard menu bar at the top of your application window, enabling users to access commands and options.

Toolbars

ToolStrip controls provide a convenient way to present frequently used commands as buttons or other controls within a toolbar.

Resources