iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
😀

Having Claude Code build a program in VS2026

に公開

Introduction

This is a record of having the AI coding assistant Claude Code write code for a Windows Forms application in Visual Studio 2026.
I decided to test what would happen if I threw a simple task at the AI—the kind of thing that appears on the first page of an introductory book: "Place one button and display a message box when it is pressed."

Environment

  • Windows 11 Pro
  • Visual Studio 2026
  • .NET Framework 4.7.2
  • Claude Code (CLI version)
  • Language: C#

We start from a completely blank state immediately after creating a new "Windows Forms App (.NET Framework)" project.

Initial Project Structure

This is the state immediately after creating WindowsFormsApp1 in VS. It contains only the following:

WindowsFormsApp1/
├── App.config
├── Form1.cs
├── Form1.Designer.cs
├── Program.cs
├── Properties/
│   ├── AssemblyInfo.cs
│   ├── Resources.Designer.cs
│   ├── Resources.resx
│   ├── Settings.Designer.cs
│   └── Settings.settings
├── WindowsFormsApp1.csproj
└── WindowsFormsApp1.slnx

Form1.cs only contains an empty constructor. Form1.Designer.cs is just the template, with only the form's size and title set.

By the way, the fact that the solution file is not the traditional .sln but .slnx (a new XML-based format) is characteristic of VS2026. Its content is simple like this:

<Solution>
  <Project Path="WindowsFormsApp1.csproj" />
</Solution>

Instructions for Claude Code

I launched Claude Code in the project folder and gave the following instructions in natural language:

Please implement the program.
Please add one button.
When the button is pressed, display a message box saying "It's a TEST" *with only an OK button and an 'i' icon.

That's all. I didn't specify any detailed API names (like MessageBox.Show or MessageBoxIcon.Information) at all.

Generated Code

Form1.Designer.cs

The button declaration and its initialization/event registration within InitializeComponent have been added.

namespace WindowsFormsApp1
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;
        // Button to be placed on the form. Displays a message box when clicked.
        private System.Windows.Forms.Button button1;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            //
            // button1
            //
            // Set button position, size, and display text
            this.button1.Location = new System.Drawing.Point(340, 200);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(120, 40);
            this.button1.TabIndex = 0;
            this.button1.Text = "Display";
            this.button1.UseVisualStyleBackColor = true;
            // Register button1_Click handler to the Click event (+= is the C# event subscription syntax)
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // Form1
            //
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(800, 450);
            // Add the button as a child control of the form (it won't appear on screen otherwise)
            this.Controls.Add(this.button1);
            this.Text = "Form1";
            this.ResumeLayout(false);
        }

        #endregion
    }
}

Form1.cs

The Click handler has been added.

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // Event handler called when button1 is clicked.
        // Displays a message box with an information icon (OK button only).
        private void button1_Click(object sender, EventArgs e)
        {
            // MessageBox.Show is the standard dialog display API.
            // Arguments are in the order of (text, title, button type, icon type).
            // MessageBoxIcon.Information corresponds to the 'i' icon.
            MessageBox.Show(
                "It's a TEST",
                "",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information);
        }
    }
}

Point Explanation

Separation of Designer.cs and Form1.cs

In WinForms, the standard practice is to separate the "code generated by the designer" and the "code you write yourself" into different files. It uses partial class to split the same Form1 class into two files.

  • Form1.Designer.cs: Code generated and managed by the designer, such as control layout, properties, and event subscriptions.
  • Form1.cs: Logic written by the human, such as the contents of event handlers.

Claude Code correctly followed this convention, splitting the button declaration/initialization into the Designer file and the Click handler into the Form1 file.

Arguments of MessageBox.Show

MessageBox.Show(text, title, button type, icon type);
  • Button type: MessageBoxButtons.OK for OK button only.
  • Icon type: MessageBoxIcon.Information for the blue 'i' icon.

There are others like Warning (yellow triangle with !), Error (red x), and Question (?).

Don't forget Controls.Add

Something beginners often get stuck on is that "just instantiating a button doesn't make it appear on the screen."
You must register it as a child control of the form with this.Controls.Add(this.button1); to make it appear on screen.
Claude Code added this as a matter of course.

Running the Program

When I execute with F5, the "Display" button appears in the center of the form.
Clicking it confirms that the "It's a TEST" dialog with a blue 'i' icon is displayed and closes with OK.

Impressions

  • Natural language instructions are sufficient. Even without memorizing API names, my intent was conveyed using UI-perspective terms like "OK button only" and "i icon."
  • It was generated with an understanding of WinForms idioms (separation from Designer.cs, necessity of Controls.Add, partial class), so it didn't feel awkward to edit by hand later.
  • The comments are also in Japanese, and it added a one-line explanation of the API's role, so it's ready to be used as-is for in-house training samples.

I feel that having Claude Code build the initial foundation is quite practical in situations where you want to create a quick verification UI but haven't touched WinForms in years.

Summary

With VS2026 + Claude Code, I was able to implement an introductory-level feature of "message box on button press" on an empty form using only natural language instructions.
The generated code follows WinForms standard practices and builds and runs as-is.
For tasks of this size, it might actually be faster than manually opening Designer.cs and clicking through properties.

Discussion