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.
Step 2 – Create a New Project
- Open Visual Studio.
- Click File → New → Project.
- Search for
Windows Forms App (.NET)and select it. - Give the project a name (e.g.,
MyFirstApp) and click Create.
Step 3 – Design the UI
Visual Studio’s Designer lets you drag controls onto the form.
- From the Toolbox, drag a
Buttononto the form. - Set its Text property to
"Click Me"in the Properties window. - Resize the form to 400 × 300 px for a clean look.
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.
Step 6 – Publish Your Application
- Right‑click the project in Solution Explorer → Publish….
- Select Folder as the target.
- Choose a folder (e.g.,
bin\Release\net6.0-windows\publish) and click Finish. - 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.