.NET UI Controls

This section provides a comprehensive guide to the various User Interface (UI) controls available in the .NET Framework, enabling you to build rich and interactive applications for desktop, web, and mobile platforms.

Understanding UI Control Categories

UI controls in .NET can generally be categorized based on their purpose and the platform they target:

Common Control Types and Examples

Buttons

Buttons are fundamental for user interaction, allowing users to trigger actions.

Example (Conceptual - WinForms/WPF):

public class MyForm : Form
{
    private Button okButton;

    public MyForm()
    {
        okButton = new Button();
        okButton.Text = "OK";
        okButton.Location = new Point(100, 100);
        okButton.Click += OkButton_Click;
        Controls.Add(okButton);
    }

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

Text Input Fields

Used for capturing user input, such as usernames, passwords, or search queries.

Common Controls: TextBox (WinForms/WPF), Entry (Xamarin.Forms), Input (HTML equivalent).

Example (Conceptual - ASP.NET Web Forms):

<asp:TextBox ID="userNameTextBox" runat="server"
    MaxLength="50"
    Placeholder="Enter your username" />

Labels

Display static text to provide information or captions for other controls.

Example (Conceptual - WPF):

<Label Content="Welcome to the application!"
       FontSize="16"
       Foreground="DarkBlue" />

List Controls

Display collections of data, allowing users to select items.

Common Controls: ListBox, ComboBox (Dropdown), DataGridView (WinForms), ListView (WPF), CollectionView (Xamarin.Forms).

Example (Conceptual - WinForms ComboBox):

public void PopulateCountries()
{
    countryComboBox.Items.Add("United States");
    countryComboBox.Items.Add("Canada");
    countryComboBox.Items.Add("Mexico");
    countryComboBox.SelectedIndex = 0;
}

Resources for Deeper Learning

Explore the following links for in-depth documentation, tutorials, and code samples: