Getting Started with Desktop Development in Visual Studio

This guide walks you through creating your first Windows desktop application using Visual Studio 2022. Follow each step, run the code, and explore the built‑in tools that make development smooth.

Step 1 – Install Visual Studio

Download and install Visual Studio 2022. During installation, select the .NET desktop development workload.

Visual Studio installer workload selection

Step 2 – Create a New Project

  1. Open Visual Studio.
  2. Click File → New → Project.
  3. Search for Windows Forms App (.NET) and select it.
  4. Give the project a name (e.g., MyFirstApp) and click Create.
New project dialog

Step 3 – Design the UI

Visual Studio’s Designer lets you drag controls onto the form.

  • From the Toolbox, drag a Button onto the form.
  • Set its Text property to "Click Me" in the Properties window.
  • Resize the form to 400 × 300 px for a clean look.
Designer view with button

Step 4 – Add Code

Double‑click the button to generate a click‑event handler and add the following code:

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Hello, World!", "Welcome", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

Press F5 to run the app. You should see a message box when clicking the button.

Step 5 – Debug & Inspect

Set a breakpoint on the MessageBox.Show line, then press F5. When the breakpoint hits, use the Locals window to inspect variables.

Debug window with breakpoint

Step 6 – Publish Your Application

  1. Right‑click the project in Solution Explorer → Publish….
  2. Select Folder as the target.
  3. Choose a folder (e.g., bin\Release\net6.0-windows\publish) and click Finish.
  4. Click Publish to generate the executable and its dependencies.

Your app is now ready for distribution.

Congratulations! You've built, run, debugged, and published a simple Windows Forms application.