Windows Forms

The Windows Forms (WinForms) technology is a managed wrapper around the native Windows API. It provides a rich set of controls and tools for building traditional desktop applications on the Windows operating system.

Key Namespaces:

  • System.Windows.Forms
  • System.Drawing

Button Control

Represents a standard Windows button control.

public class Button : Control
Properties:
  • Text: string - Gets or sets the text displayed on the button.
  • Enabled: bool - Gets or sets a value indicating whether the control can respond to user interaction.
  • BackColor: Color - Gets or sets the background color of the control.
Events:
  • Click: EventHandler - Occurs when the button is clicked.

Example Usage:

// Creating a button instance Button myButton = new Button(); myButton.Text = "Click Me"; myButton.Location = new System.Drawing.Point(50, 50); // Attaching a click event handler myButton.Click += (object sender, EventArgs e) => { MessageBox.Show("Button was clicked!"); }; // Adding the button to a form this.Controls.Add(myButton);

TextBox Control

Represents a Windows text box control for user input.

public class TextBox : Control
Properties:
  • Text: string - Gets or sets the current text in the text box.
  • Multiline: bool - Gets or sets a value indicating whether the text box is a multiline text box.
  • ReadOnly: bool - Gets or sets a value indicating whether the text in the text box is read-only.
Events:
  • TextChanged: EventHandler - Occurs when the text in the text box changes.

Example Usage:

TextBox myTextBox = new TextBox(); myTextBox.Text = "Enter text here..."; myTextBox.Width = 200; myTextBox.TextChanged += (sender, e) => { Console.WriteLine("Text changed to: " + myTextBox.Text); }; this.Controls.Add(myTextBox);

WPF (Windows Presentation Foundation)

WPF is a UI framework that enables rich, interactive user experiences. It uses XAML for declarative UI design and a vector-based rendering engine for high-quality graphics.

Key Namespaces:

  • System.Windows
  • System.Windows.Controls
  • System.Windows.Markup

Button Element (XAML)

Represents a button in WPF, typically defined using XAML.

Example XAML:

<Button Content="Click Me WPF" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="30" Click="MyButton_Click"/>

Example C# (Code-behind):

private void MyButton_Click(object sender, RoutedEventArgs e) { MessageBox.Show("WPF Button Clicked!"); }

Grid Layout Panel

A flexible panel that arranges its children in a table-like structure of rows and columns.

Example XAML:

<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <TextBlock Text="Label:" Grid.Row="0" Grid.Column="0" Margin="5"/> <TextBox Grid.Row="0" Grid.Column="1" Margin="5"/> <Button Content="Submit" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10"/> </Grid>

.NET MAUI

A cross-platform framework for developing native mobile and desktop applications with C# and XAML from a single codebase.

Key Namespaces:

  • Microsoft.Maui.Controls

Button Control (MAUI)

Represents a button in a MAUI application.

Example XAML:

<Button Text="MAUI Button" Clicked="OnButtonClicked" />

Example C# (Code-behind):

private void OnButtonClicked(object sender, EventArgs e) { DisplayAlert("Info", "MAUI button pressed!", "OK"); }

Layout Panels (MAUI)

MAUI provides various layout options like StackLayout, Grid, and FlexLayout for arranging UI elements.

<StackLayout> <Label Text="Welcome to MAUI!" /> <Entry Placeholder="Enter your name"/> <Button Text="Save" /> </StackLayout>

ASP.NET Web Forms

An older technology for building dynamic web applications using a server-side control model and event-driven programming.

Key Namespaces:

  • System.Web.UI
  • System.Web.UI.WebControls

Button Control (Web Forms)

Represents a button that can trigger server-side events.

Example ASPX Markup:

<asp:Button ID="SubmitButton" runat="server" Text="Submit" OnClick="SubmitButton_Click"/>

Example C# (Code-behind):

protected void SubmitButton_Click(object sender, EventArgs e) { Response.Write("Form submitted from Web Forms!"); }