MSDN

.NET Desktop Development

Comprehensive guides, API references, and tutorials for building Windows desktop applications with .NET.

Table of Contents

Getting Started

Begin building desktop applications with .NET by installing the latest .NET SDK and Visual Studio.

Prerequisites

Creating Your First App

dotnet new winforms -n MyFirstWinFormsApp
cd MyFirstWinFormsApp
dotnet run

Windows Forms

Windows Forms provides a rapid‑application development (RAD) environment for building rich UI on Windows.

Key Topics

Sample Code

using System;
using System.Windows.Forms;

public class MainForm : Form
{
    public MainForm()
    {
        Text = "Hello, Windows Forms!";
        Width = 400;
        Height = 300;

        var button = new Button { Text = "Click Me", Dock = DockStyle.Fill };
        button.Click += (s, e) => MessageBox.Show("Button clicked!");
        Controls.Add(button);
    }
}

static class Program
{
    [STAThread]
    static void Main()
    {
        Application.SetHighDpiMode(HighDpiMode.SystemAware);
        Application.EnableVisualStyles();
        Application.Run(new MainForm());
    }
}

Windows Presentation Foundation (WPF)

WPF enables modern UI with XAML, data binding, and hardware‑accelerated graphics.

Getting Started with XAML

<Window x:Class="WpfApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WPF Sample" Height="300" Width="400">
    <Grid>
        <Button Content="Press Me"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Click="Button_Click"/>
    </Grid>
</Window>
using System.Windows;

namespace WpfApp
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Hello, WPF!");
        }
    }
}

Sample Projects

API Reference

Explore the full .NET desktop API documentation:

Additional Resources