Token导航 LogoToken导航

Agent Skill · 前端设计

dotnet-winforms-basics(dotnet winform 基础知识)

dotnet-winforms-basics 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

dotnet-winforms-basics 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 3,296。

总安装 1,411周安装 60GitHub Stars 16下载 494核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:dotnet-winforms-basics(dotnet winform 基础知识)
来源仓库:https://github.com/wshaddix/dotnet-skills
仓库路径:skills/dotnet-winforms-basics
安装命令:
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-winforms-basics
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-winforms-basics

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

介绍 .NET 8+ 下的 WinForms 现代化开发。支持高 DPI、深色模式和依赖注入集成。提供从 .NET Framework 迁移的现代实践。适用于桌面应用维护与体验升级参考。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

dotnet-winforms-basics 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/dotnet-winforms-basics

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-winforms…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

dotnet-winforms-basics 怎么安装?

在终端执行 npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-winforms-basics。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

dotnet-winforms-basics 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

dotnet-winforms-basics 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

dotnet-winforms-basics 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

dotnet-winforms-basics 用的人多吗?

公开数据是累计安装 1,411 次,近一周安装 60 次,下载 494 次,GitHub 16 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

dotnet-winforms-basics 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
dotnet-winforms-basics

dotnet winform 基础知识 · 本页

1,41116需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

dotnet-winforms-basics

WinForms on.NET 8+: updated project templates with Host builder and DI, high-DPI support with PerMonitorV2, dark mode via Application.SetColorMode (experimental in.NET 9, targeting finalization in.NET 11), when to use WinForms, modernization tips for migrating from.NET Framework, and common agent pitfalls.

Version assumptions:.NET 8.0+ baseline (current LTS). TFM net8.0-windows..NET 9 features (dark mode experimental) explicitly marked..NET 11 finalization targets noted.

Scope boundary: This skill owns WinForms on modern.NET patterns: project setup, high-DPI, dark mode, DI, when to use, modernization. Migration from.NET Framework to.NET 8+ is owned by [skill:dotnet-wpf-migration]. Desktop testing is owned by [skill:dotnet-ui-testing-core].

Out of scope: WinForms.NET Framework patterns (legacy) -- this skill covers.NET 8+ only. Migration guidance -- see [skill:dotnet-wpf-migration]. Desktop testing -- see [skill:dotnet-ui-testing-core]. General Native AOT patterns -- see [skill:dotnet-native-aot]. UI framework selection -- see [skill:dotnet-ui-chooser].

Cross-references: [skill:dotnet-ui-testing-core] for desktop testing, [skill:dotnet-wpf-modern] for WPF patterns, [skill:dotnet-winui] for WinUI 3 patterns, [skill:dotnet-wpf-migration] for migration guidance, [skill:dotnet-native-aot] for general AOT, [skill:dotnet-ui-chooser] for framework selection.


.NET 8+ Differences

WinForms on.NET 8+ is a significant modernization from.NET Framework WinForms, with an SDK-style project format, DI support, and updated APIs.

New Project Template

<!-- MyWinFormsApp.csproj (SDK-style) -->
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.*" />
  </ItemGroup>
</Project>

Key differences from.NET Framework WinForms:

  • SDK-style .csproj (no packages.config, no AssemblyInfo.cs)
  • Nullable reference types enabled by default
  • Implicit usings enabled
  • NuGet PackageReference format
  • Program.cs uses top-level statements
  • dotnet publish produces a single deployment artifact
  • Side-by-side.NET installation (no machine-wide framework dependency)

Host Builder Pattern

Modern WinForms apps use the generic host for dependency injection:

// Program.cs
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

ApplicationConfiguration.Initialize();

var host = Host.CreateDefaultBuilder()
    .ConfigureServices((context, services) =>
    {
        // Services
        services.AddSingleton<IProductService, ProductService>();
        services.AddSingleton<ISettingsService, SettingsService>();

        // HTTP client
        services.AddHttpClient("api", client =>
        {
            client.BaseAddress = new Uri("https://api.example.com");
        });

        // Forms
        services.AddTransient<MainForm>();
        services.AddTransient<ProductDetailForm>();
    })
    .Build();

var mainForm = host.Services.GetRequiredService<MainForm>();
Application.Run(mainForm);
// MainForm.cs -- constructor injection
public partial class MainForm : Form
{
    private readonly IProductService _productService;
    private readonly IServiceProvider _serviceProvider;

    public MainForm(IProductService productService, IServiceProvider serviceProvider)
    {
        _productService = productService;
        _serviceProvider = serviceProvider;
        InitializeComponent();
    }

    private async void btnLoad_Click(object sender, EventArgs e)
    {
        var products = await _productService.GetProductsAsync();
        dataGridProducts.DataSource = products.ToList();
    }

    private void btnDetails_Click(object sender, EventArgs e)
    {
        var detailForm = _serviceProvider.GetRequiredService<ProductDetailForm>();
        detailForm.ShowDialog();
    }
}

ApplicationConfiguration.Initialize

.NET 8+ WinForms uses ApplicationConfiguration.Initialize() as the entry point, which consolidates multiple legacy configuration calls:

// ApplicationConfiguration.Initialize() is equivalent to:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetHighDpiMode(HighDpiMode.SystemAware);  // default; override below for PerMonitorV2

High-DPI

WinForms on.NET 8+ has significantly improved high-DPI support. The recommended mode is PerMonitorV2, which handles per-monitor DPI changes automatically.

Enabling PerMonitorV2

// Program.cs -- set before ApplicationConfiguration.Initialize()
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
ApplicationConfiguration.Initialize();
// Note: SetHighDpiMode() called before Initialize() takes precedence
// over the default SystemAware mode set by Initialize().

Or configure via runtimeconfig.json:

{
  "runtimeOptions": {
    "configProperties": {
      "System.Windows.Forms.ApplicationHighDpiMode": 3
    }
  }
}

High-DPI modes:

ModeValueBehavior
DpiUnaware0No scaling; system bitmap-stretches the window
SystemAware1Scales to primary monitor DPI at startup (default in.NET 8)
PerMonitor2Adjusts when moved between monitors (basic)
PerMonitorV23Full per-monitor scaling with non-client area support (recommended)
DpiUnawareGdiScaled4DPI-unaware but GDI+ text renders at native resolution

DPI-Unaware Designer Mode (.NET 9+)

.NET 9 introduces a DPI-unaware designer mode that prevents layout scaling issues in the Visual Studio WinForms designer. The designer renders at 96 DPI regardless of system DPI, preventing corrupted .Designer.cs files.

<!-- .csproj: opt in to DPI-unaware designer (.NET 9+) -->
<PropertyGroup>
  <ForceDesignerDPIUnaware>true</ForceDesignerDPIUnaware>
</PropertyGroup>

Scaling Gotchas

  • Do not use absolute pixel sizes for controls. Use AutoScaleMode.Dpi on forms and let the layout engine scale controls automatically.
  • Anchor and Dock layouts scale better than absolute positioning. TableLayoutPanel and FlowLayoutPanel handle DPI changes more reliably than fixed-position controls.
  • Custom drawing (OnPaint) must use DPI-aware coordinates. Scale drawing coordinates by DeviceDpi / 96.0f in OnPaint overrides.
  • Image resources need multiple resolutions. Provide 1x, 1.5x, and 2x versions of icons and images, or use SVG-based rendering.
// DPI-aware custom drawing
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    float scale = DeviceDpi / 96.0f;
    float fontSize = 12.0f * scale;
    using var font = new Font("Segoe UI", fontSize);
    e.Graphics.DrawString("Scaled text", font, Brushes.Black, 10 * scale, 10 * scale);
}

Dark Mode

WinForms dark mode is experimental in.NET 9 and is targeting finalization in.NET 11. It provides system-integrated dark mode for WinForms controls using the Windows dark mode APIs.

Enabling Dark Mode (.NET 9+ Experimental)

// Program.cs -- set before ApplicationConfiguration.Initialize()
Application.SetColorMode(SystemColorMode.Dark);
ApplicationConfiguration.Initialize();

Or follow system theme:

// Follow system light/dark preference
Application.SetColorMode(SystemColorMode.System);

SystemColorMode values:

ModeBehavior
ClassicStandard WinForms colors (no dark mode)
SystemFollow Windows system light/dark theme setting
DarkForce dark mode

Dark Mode Caveats

  • Experimental status: The API surface may change before.NET 11 finalization. Do not depend on specific color values or rendering behavior in production.
  • Control coverage: Not all controls support dark mode in.NET 9. Standard controls (Button, TextBox, Label, ListBox, DataGridView) have dark mode support. Third-party and custom-drawn controls may not render correctly.
  • Owner-drawn controls: Controls using DrawMode.OwnerDrawFixed or custom OnPaint overrides must manually read SystemColors to respond to dark mode. They do not automatically inherit dark mode colors.
  • Windows version: Dark mode requires Windows 10 version 1809 (build 17763) or later.
  • .NET 11 target: Microsoft has indicated that WinForms visual styles (including dark mode) are targeting finalization in.NET 11. Plan for API stability after that release.
// Owner-drawn controls must use SystemColors for dark mode compatibility
protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    // Use SystemColors instead of hardcoded colors
    using var textBrush = new SolidBrush(SystemColors.ControlText);
    using var bgBrush = new SolidBrush(SystemColors.Control);
    e.Graphics.FillRectangle(bgBrush, ClientRectangle);
    e.Graphics.DrawString("Text", Font, textBrush, 10, 10);
}

When to Use

WinForms is the right choice for specific scenarios. It is not a general-purpose UI framework for new customer-facing applications.

Good Fit

  • Rapid prototyping: Drag-and-drop designer for quick internal tools and proof-of-concept UIs
  • Internal enterprise tools: Line-of-business forms, data entry, CRUD applications with DataGridView
  • Simple Windows-only utilities: System tray apps, configuration tools, diagnostics dashboards
  • Existing WinForms maintenance: Modernizing existing.NET Framework WinForms apps to.NET 8+
  • Data-heavy tabular UIs: DataGridView with virtual mode handles millions of rows efficiently

Not a Good Fit

  • New customer-facing applications: Use WPF (rich Windows desktop), WinUI 3 (modern Windows), MAUI (cross-platform), or Blazor (web)
  • Complex custom UI: WinForms controls are limited in styling; WPF or WinUI provide rich templating
  • Cross-platform requirements: WinForms is Windows-only; use MAUI or Uno Platform
  • Accessibility-first applications: WPF and WinUI have better accessibility APIs and screen reader support
  • Touch-optimized interfaces: WinForms was designed for mouse/keyboard; WinUI or MAUI handle touch better

Decision Guidance

ScenarioRecommended Framework
Quick internal toolWinForms
Data entry form (Windows)WinForms or WPF
Modern Windows desktop appWinUI 3 or WPF (.NET 9+ Fluent)
Cross-platform mobile + desktopMAUI or Uno Platform
Cross-platform + webUno Platform or Blazor
Existing WinForms modernizationWinForms on.NET 8+

For the full framework decision tree, see [skill:dotnet-ui-chooser].


Modernization Tips

Tips for modernizing existing.NET Framework WinForms applications to.NET 8+.

Add Dependency Injection

Replace static references and singletons with constructor injection via Host builder (see.NET 8+ Differences section above).

Before (legacy pattern):

// Anti-pattern: static service references
public partial class MainForm : Form
{
    private void btnLoad_Click(object sender, EventArgs e)
    {
        var products = ProductService.Instance.GetProducts();
        dataGridProducts.DataSource = products;
    }
}

After (modern pattern):

// Modern: constructor injection
public partial class MainForm : Form
{
    private readonly IProductService _productService;

    public MainForm(IProductService productService)
    {
        _productService = productService;
        InitializeComponent();
    }

    private async void btnLoad_Click(object sender, EventArgs e)
    {
        var products = await _productService.GetProductsAsync();
        dataGridProducts.DataSource = products.ToList();
    }
}

Use Async Patterns

Replace synchronous blocking calls with async/await to keep the UI responsive:

// Before: blocks UI thread
private void btnSave_Click(object sender, EventArgs e)
{
    var client = new HttpClient();
    var result = client.PostAsync(url, content).Result; // BLOCKS UI
    MessageBox.Show("Saved!");
}

// After: async keeps UI responsive
private async void btnSave_Click(object sender, EventArgs e)
{
    btnSave.Enabled = false;
    try
    {
        var result = await _httpClient.PostAsync(url, content);
        result.EnsureSuccessStatusCode();
        MessageBox.Show("Saved!");
    }
    catch (HttpRequestException ex)
    {
        MessageBox.Show($"Error: {ex.Message}");
    }
    finally
    {
        btnSave.Enabled = true;
    }
}

Convert to.NET 8+

Use the.NET Upgrade Assistant for automated migration:

# Install upgrade assistant
dotnet tool install -g upgrade-assistant

# Analyze the project
upgrade-assistant analyze MyWinFormsApp.csproj

# Upgrade the project
upgrade-assistant upgrade MyWinFormsApp.csproj

Common migration issues:

  • App.config settings need manual migration to appsettings.json or Host builder configuration
  • My.Settings (VB.NET) and Settings.settings need manual migration
  • Third-party controls may not have.NET 8 compatible versions
  • Designer-generated code in .Designer.cs files usually migrates cleanly
  • COM interop (System.Runtime.InteropServices) syntax may differ

Adopt Modern C# Features

// File-scoped namespaces
namespace MyApp.Forms;

// Null-conditional event invocation
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));

// Collection expressions
var columns = new[] { "Name", "Price", "Category" };

// Primary constructors for services (C# 12)
public class ProductService(HttpClient httpClient) : IProductService
{
    public async Task<List<Product>> GetProductsAsync()
        => await httpClient.GetFromJsonAsync<List<Product>>("/products") ?? [];
}

Agent Gotchas

  1. Do not recommend WinForms for new customer-facing applications. WinForms is appropriate for internal tools, rapid prototyping, and data-centric utilities. For customer-facing apps, recommend WPF, WinUI 3, MAUI, or Blazor depending on requirements.
  2. Do not use deprecated WinForms APIs. Menu (use MenuStrip), MainMenu (use MenuStrip), ContextMenu (use ContextMenuStrip), StatusBar (use StatusStrip), ToolBar (use ToolStrip), DataGrid (use DataGridView).
  3. Do not assume dark mode is production-ready. Dark mode via Application.SetColorMode is experimental in.NET 9 and targeting finalization in.NET 11. API surface and rendering may change.
  4. Do not use HighDpiMode.SystemAware without testing multi-monitor scenarios. PerMonitorV2 is recommended for apps used on multi-monitor setups with different DPI settings.
  5. Do not block the UI thread with synchronous calls. Use async void for event handlers and async Task for all other async methods. Never use .Result or .Wait() on the UI thread.
  6. Do not use Control.Invoke when await suffices. In.NET 8+ WinForms, await automatically marshals back to the UI thread via SynchronizationContext. Manual Invoke/BeginInvoke is only needed when called from non-async code (timers, COM callbacks).
  7. Do not hardcode colors when dark mode is enabled. Use SystemColors properties (e.g., SystemColors.ControlText, SystemColors.Control) in custom drawing and owner-drawn controls to respond correctly to theme changes.
  8. Do not forget to call ApplicationConfiguration.Initialize() before Application.Run. Omitting it disables visual styles and high-DPI configuration.

Prerequisites

  • .NET 8.0+ with Windows desktop workload
  • TFM: net8.0-windows (no Windows SDK version needed for WinForms)
  • Visual Studio 2022+ with Windows desktop workload (for designer support)
  • For dark mode:.NET 9+ (experimental), Windows 10 version 1809+
  • For DPI-unaware designer:.NET 9+

References

平台分布

Codex

34.5%
按下载量换算170

Claude

34.17%
按下载量换算169

Cursor

18.15%
按下载量换算90

Gemini CLI

9.79%
按下载量换算48

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills