Desktop Controls (.NET)

This section provides comprehensive documentation on the various controls available for building rich Windows desktop applications using the .NET Framework and .NET Core.

Introduction to Controls

Controls are the fundamental building blocks of a graphical user interface (GUI). They represent visual elements that users interact with, such as buttons, text boxes, labels, and lists. .NET provides a rich set of pre-built controls that simplify the development of user-friendly Windows applications.

Key Control Categories

The available controls can be broadly categorized based on their functionality:

Commonly Used Controls

Button Control

The Button control is used to initiate an action when clicked by the user.

Namespace: System.Windows.Forms
Class: Button

Properties:

Events:

Example: Handling Button Click


using System;
using System.Windows.Forms;

public class MyForm : Form
{
    private Button myButton;

    public MyForm()
    {
        myButton = new Button();
        myButton.Text = "Click Me";
        myButton.Location = new System.Drawing.Point(50, 50);
        myButton.Click += new EventHandler(MyButton_Click);
        this.Controls.Add(myButton);
    }

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

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MyForm());
    }
}
            

TextBox Control

The TextBox control allows users to enter and display text. It supports single-line and multi-line input.

Namespace: System.Windows.Forms
Class: TextBox

Properties:

Example: Getting Text from a TextBox


string userInput = myTextBox.Text;
MessageBox.Show($"You entered: {userInput}");
            

Label Control

The Label control is used to display static text, such as titles, descriptions, or instructions, to the user.

Namespace: System.Windows.Forms
Class: Label

Properties:

Designing Your UI

You can add controls to your forms using the Visual Studio Designer or programmatically. The designer provides a drag-and-drop interface for arranging controls and setting their properties visually.

Tips for effective UI design:

Further Reading

Explore the links below for detailed information on specific controls and advanced UI design techniques: