Agent skill

dotnet-winforms

Build, maintain, or modernize Windows Forms applications with practical guidance on designer-driven UI, event handling, data binding, MVP separation, and migration to modern .NET. Use when working on WinForms projects or migrating from .NET Framework.

Stars 302
Forks 22

Install this agent skill to your Project

npx add-skill https://github.com/managedcode/dotnet-skills/tree/main/catalog/Frameworks/WinForms/skills/dotnet-winforms

SKILL.md

Windows Forms

Trigger On

  • working on Windows Forms UI, event-driven workflows, or classic LOB applications
  • migrating WinForms from .NET Framework to modern .NET
  • cleaning up oversized form code or designer coupling
  • implementing data binding, validation, or control customization

Workflow

  1. Respect designer boundaries — never edit .Designer.cs directly; changes are lost on regeneration.
  2. Separate business logic from forms — use MVP (Model-View-Presenter) pattern. Forms orchestrate UI; presenters contain logic; services handle data access.
    csharp
    // View interface — forms implement this
    public interface ICustomerView
    {
        string CustomerName { get; set; }
        event EventHandler SaveRequested;
        void ShowError(string message);
    }
    
    // Presenter — testable without UI
    public class CustomerPresenter
    {
        private readonly ICustomerView _view;
        private readonly ICustomerService _service;
        public CustomerPresenter(ICustomerView view, ICustomerService service)
        {
            _view = view;
            _service = service;
            _view.SaveRequested += async (s, e) =>
            {
                try { await _service.SaveAsync(_view.CustomerName); }
                catch (Exception ex) { _view.ShowError(ex.Message); }
            };
        }
    }
    
  3. Use DI from Program.cs (.NET 6+):
    csharp
    var services = new ServiceCollection();
    services.AddSingleton<ICustomerService, CustomerService>();
    services.AddTransient<MainForm>();
    using var sp = services.BuildServiceProvider();
    Application.Run(sp.GetRequiredService<MainForm>());
    
  4. Use data binding via BindingSource and INotifyPropertyChanged instead of manual control population. See references/patterns.md for complete binding patterns.
  5. Use async/await for I/O operations — disable controls during loading, use Progress<T> for progress reporting. Never block the UI thread.
  6. Validate with ErrorProvider and the Validating event. Call ValidateChildren() before save operations.
  7. Modernize incrementally — prefer better structure over big-bang rewrites. Use .NET 8+ features (button commands, stock icons) when available.
mermaid
flowchart LR
  A["Form event"] --> B["Presenter handles logic"]
  B --> C["Service layer / data access"]
  C --> D["Update view via interface"]
  D --> E["Validate and display results"]

Key Decisions

Decision Guidance
MVP vs MVVM Prefer MVP for WinForms — simpler with event-driven model
BindingSource vs manual Always prefer BindingSource for list/detail binding
Sync vs async I/O Always async — use async void only for event handlers
Custom controls Extract reusable UserControl when form grows beyond ~300 lines
.NET Framework → .NET Use the official migration guide; validate designer compatibility first

Deliver

  • less brittle form code with clear UI/logic separation
  • MVP pattern with testable presenters
  • pragmatic modernization guidance for WinForms-heavy apps
  • data binding and validation patterns that reduce manual wiring

Validate

  • designer files stay stable and are not hand-edited
  • forms are not acting as the application service layer
  • async operations do not block the UI thread
  • validation is implemented consistently with ErrorProvider
  • Windows-only runtime behavior is tested on target

References

  • references/patterns.md - WinForms architectural patterns (MVP, MVVM, Passive View), data binding, validation, form communication, threading, DI setup, and .NET 8+ features
  • references/migration.md - step-by-step migration from .NET Framework to modern .NET, common issues, deployment options, and gradual migration strategies

Expand your agent's capabilities with these related and highly-rated skills.

managedcode/dotnet-skills

dotnet-project-setup

Create or reorganize .NET solutions with clean project boundaries, repeatable SDK settings, and a maintainable baseline for libraries, apps, tests, CI, and local development.

302 22
Explore
managedcode/dotnet-skills

csharp-scripts

Run single-file C# programs as scripts (file-based apps) for quick experimentation, prototyping, and concept testing. Use when the user wants to write and execute a small C# program without creating a full project.

302 22
Explore
managedcode/dotnet-skills

dotnet-pinvoke

Correctly call native (C/C++) libraries from .NET using P/Invoke and LibraryImport. Covers function signatures, string marshalling, memory lifetime, SafeHandle, and cross-platform patterns. USE FOR: writing new P/Invoke or LibraryImport declarations, reviewing or debugging existing native interop code, wrapping a C or C++ library for use in .NET, diagnosing crashes, memory leaks, or corruption at the managed/native boundary. DO NOT USE FOR: COM interop, C++/CLI mixed-mode assemblies, or pure managed code with no native dependencies.

302 22
Explore
managedcode/dotnet-skills

nuget-trusted-publishing

Set up NuGet trusted publishing (OIDC) on a GitHub Actions repo — replaces long-lived API keys with short-lived tokens. USE FOR: trusted publishing, NuGet OIDC, keyless NuGet publish, migrate from NuGet API key, NuGet/login, secure NuGet publishing. DO NOT USE FOR: publishing to private feeds or Azure Artifacts (OIDC is nuget.org only). INVOKES: shell (powershell or bash), edit, create, ask_user for guided repo setup.

302 22
Explore
managedcode/dotnet-skills

dotnet-legacy-aspnet

Maintain classic ASP.NET applications on .NET Framework, including Web Forms, older MVC, and legacy hosting patterns, while planning realistic modernization boundaries.

302 22
Explore
managedcode/dotnet-skills

dotnet-code-review

Review .NET changes for bugs, regressions, architectural drift, missing tests, incorrect async or disposal behavior, and platform-specific pitfalls before you approve or merge them.

302 22
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results