# Windows Forms

**Windows Forms**（WinForms）是用于在 .NET 上构建 Windows 桌面客户端应用程序的用户界面框架。它是 Windows 用户界面库——主要是 User32 和 GDI+——的托管包装器，提供窗体、可复用控件、图形、数据绑定和用户输入处理<sup>[1](https://github.com/dotnet/winforms/)</sup><sup> • </sup><sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup>。窗体是应用程序借以显示信息的可视表面；控件是该表面上的离散元素，用于显示数据或接受输入<sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup>。当时的专业文献将其描述为“.NET 在客户端的面孔”，一个基于窗体的环境，旨在融合此前各种 UI 对象模型的优势<sup>[3](https://www.informit.com/store/windows-forms-programming-in-c-sharp-9780321116208)</sup>。

目前存在两种实现：在 GitHub 上为现代 .NET 开发的开源版本，以及微软作为 Windows 操作系统组件分发的 .NET Framework 4 版本<sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup>。

| 关键事实 | 详情 |
|---|---|
| 是什么 | 用于 Windows 桌面应用的 .NET UI 框架，包装 User32 和 GDI+；支持控件、图形、数据绑定和用户输入<sup>[1](https://github.com/dotnet/winforms/)</sup><sup> • </sup><sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup> |
| 推出时间 | 2002 年 2 月 13 日，随 .NET Framework 1.0 发布，定位为 Windows 应用的快速应用程序开发工具<sup>[1](https://github.com/dotnet/winforms/)</sup> |
| 开源 | WPF、WinForms 和 WinUI 于 2018 年 12 月 4 日在 GitHub 上以 MIT 许可证开源<sup>[4](https://visualstudiomagazine.com/articles/2018/12/04/net-open-source.aspx)</sup><sup> • </sup><sup>[1](https://github.com/dotnet/winforms/)</sup> |
| 平台范围 | 仅限 Windows；底层的 .NET（Core）运行时本身跨平台运行<sup>[5](https://www.hanselman.com/blog/announcing-wpf-winforms-and-winui-are-going-open-source)</sup> |
| 渲染 | 相比 WPF 在 DirectX 之上的丰富层，WinForms 是 GDI+ 之上较薄的一层<sup>[6](https://raw.githubusercontent.com/dotnet-architecture/eBooks/main/current/modernize-desktop-apps/Modernize-Desktop-Apps-on-Windows-with-NET.pdf)</sup> |
| 最新版本 | 适用于 .NET 10 的 Windows Forms，2025 年 11 月发布；.NET 9 文档指定 Visual Studio 2022 版本 17.12<sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup><sup> • </sup><sup>[7](https://developer.mescius.com/blogs/winui-vs-wpf-winforms-uwp-and-mfc)</sup><sup> • </sup><sup>[12](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/whats-new/net100)</sup> |
| 开发者群体 | 据仓库维护者称，Visual Basic .NET 开发者约占 WinForms 开发者的 20%<sup>[1](https://github.com/dotnet/winforms/)</sup> |

## 历史

微软于 2002 年 2 月 13 日随 .NET Framework 1.0 一同发布了 WinForms。其主要焦点过去是、现在仍然是 Windows 的快速应用程序开发：开发者以可视化方式组装界面，由设计器生成代码<sup>[1](https://github.com/dotnet/winforms/)</sup><sup> • </sup><sup>[7](https://developer.mescius.com/blogs/winui-vs-wpf-winforms-uwp-and-mfc)</sup>。最初的设计器在 devenv.exe 进程内运行，生成的 `InitializeComponent()` 方法对于复杂窗体可能长达数百行，而高 DPI 支持几乎不存在<sup>[8](https://docs.lextudio.com/blog/a-brief-history-of-net-core-winforms-designer/)</sup>。

设计器在 2002 年至 2010 年前后经历了其最辉煌的时期。2006 年 WPF 随 .NET 3.0 问世，带来了声明式 XAML 标记和分辨率无关的图形，使微软的宣传重心转向 WPF 为未来、WinForms 为遗留<sup>[7](https://developer.mescius.com/blogs/winui-vs-wpf-winforms-uwp-and-mfc)</sup><sup> • </sup><sup>[8](https://docs.lextudio.com/blog/a-brief-history-of-net-core-winforms-designer/)</sup>。

该框架的现代阶段始于 2018 年 12 月 4 日，微软借 Connect(); 2018 大会之机宣布 WPF、WinForms 和 WinUI 在 GitHub 上开源<sup>[4](https://visualstudiomagazine.com/articles/2018/12/04/net-open-source.aspx)</sup>。开源适用于运行于 Windows 的 .NET Core 3 版本，而 .NET Core 3 本身跨平台运行于 Windows、Linux 和 macOS，并可在容器和云中运行<sup>[5](https://www.hanselman.com/blog/announcing-wpf-winforms-and-winui-are-going-open-source)</sup>。

## 架构与工作原理

WinForms 是 Win32 API 集的托管包装器，它一直严重依赖互操作层与非托管 Windows 组件通信<sup>[1](https://github.com/dotnet/winforms/)</sup><sup> • </sup><sup>[9](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/)</sup>。应用程序通过向窗体添加控件并响应鼠标点击和按键等事件来构建<sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup>。[Visual Studio](https://www.edgepedia.org/zh/visual-studio) 拖放设计器提供网格线和对齐线，以及用于高级布局的 FlowLayoutPanel、TableLayoutPanel 和 SplitContainer<sup>[2](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)</sup>。

渲染历来依赖 GDI+（部分使用 GDI）。GDI+ 比 GDI 更易使用，因为它抽象了设备上下文，但由于额外开销而较慢；在涉及纯色和画笔的场景中，微软在 .NET 5.0 中改用了 GDI<sup>[9](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/)</sup>。与渲染相关的 API（如 PaintEventArgs）通过 IDeviceContext 接口进行了扩展，以绕过 GDI+ 的 Graphics 对象，某些情况下重绘路径的内存分配量降至原来的十分之一<sup>[9](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/)</sup>。.NET Core 的工作还使互操作结构体可直接传递（blittable），并倾向于使用更高效的“W”（Unicode）函数<sup>[9](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/)</sup>。

**数据绑定。** 在 .NET 7 中，微软引入了更现代的数据绑定形式的预览版，包含数据上下文和命令模式，类似于 WPF 提供的绑定，支持 MVVM 风格的模式。微软同时表示没有计划在 Windows Forms 中引入 XAML 支持<sup>[10](https://devblogs.microsoft.com/dotnet/winforms-enhancements-in-dotnet-7/)</sup>。

## 与 WPF、WinUI 3 及其他框架的比较

微软架构电子书直接划出了核心区别：WPF 可以视为 DirectX 之上的丰富层，而 Windows Forms 是 GDI+ 之上较薄的一层<sup>[6](https://raw.githubusercontent.com/dotnet-architecture/eBooks/main/current/modernize-desktop-apps/Modernize-Desktop-Apps-on-Windows-with-NET.pdf)</sup>。WPF 于 2006 年随 .NET 3.0 发布，作为 WinForms 的潜在替代品，用 XAML 定义 UI，构建于 DirectX 之上；WinForms 用设计器生成的 C# 或 VB.NET 代码定义 UI，使用遗留的 GDI+ 图形库<sup>[7](https://developer.mescius.com/blogs/winui-vs-wpf-winforms-uwp-and-mfc)</sup>。两种技术自 3.0 版起都是 .NET（Core）的一部分，都仅限 Windows，且都有开源的 .NET 实现<sup>[6](https://raw.githubusercontent.com/dotnet-architecture/eBooks/main/current/modernize-desktop-apps/Modernize-Desktop-Apps-on-Windows-with-NET.pdf)</sup>。

项目自身声明的非目标标明了其雄心边界：维护者排除 WPF 或 WinUI 等现代桌面 UI 已有的新功能，以及将桌面应用延伸至移动、多媒体或物联网的功能<sup>[1](https://github.com/dotnet/winforms/)</sup>。

## 数据一览

启动开销一直是一个明确的优化目标。基线测量显示，.NET Framework WinForms 在启动时于 406 毫秒内分配了 5.6K 个对象，其中最大的一块——2.4K 个对象——来自 System.Configuration；.NET Core 为 414 毫秒内 4.9K 个。工程改进将其降至 394 毫秒内 1.6K 个，总体从约 5,000 个对象降至约 1,500 个，分配的总字节数下降约 20%<sup>[11](https://github.com/dotnet/corefx/pull/39275)</sup>。单次初始调用 `Graphics.FromHwnd(IntPtr.Zero)` 从大约 3,600 次分配降至 196 次，时间从 32 毫秒缩短至 12 毫秒<sup>[11](https://github.com/dotnet/corefx/pull/39275)</sup>。

在采用率方面，Telerik 2016 年 4 月的一项调查将 Windows Forms、WPF 和 UWP 列为最受欢迎的 Windows 桌面技术，该电子书将 2002 年首次发布的 WinForms 描述为构建于 Windows GDI 引擎之上的最古老、使用最广泛的桌面技术<sup>[6](https://raw.githubusercontent.com/dotnet-architecture/eBooks/main/current/modernize-desktop-apps/Modernize-Desktop-Apps-on-Windows-with-NET.pdf)</sup>。约 20% 的 WinForms 开发者使用 [Visual Basic](https://www.edgepedia.org/zh/visual-basic) .NET 编写<sup>[1](https://github.com/dotnet/winforms/)</sup>。

## 近期发展

**高 DPI 工作。** .NET 7 在 PerMonitorV2 多显示器场景中继续推进高 DPI 工作。它修复了嵌套控件的缩放问题，该问题由消息顺序引起——父控件在所有子控件已完成自身缩放后才收到 WM_DPICHANGED 消息；对于以 PerMonitorV2 设置 ApplicationHighDpiMode 运行的应用程序，它根据当前显示器的 DPI 缩放 Form.MaximumSize 和 Form.MinimumSize<sup>[10](https://devblogs.microsoft.com/dotnet/winforms-enhancements-in-dotnet-7/)</sup>。

**深色模式和异步窗体。** 2025 年 11 月发布的 .NET 10 提供了完全集成的深色模式支持和完全集成的异步窗体支持；Application.SetColorMode API 不再是实验性的，深色模式不再受编译器错误 WFO5001 的限制<sup>[12](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/whats-new/net100)</sup>。异步任务现在持有窗体的弱引用，使 UI 在管理多个窗口时保持响应灵敏<sup>[12](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/whats-new/net100)</sup>。.NET 10 还增加了自定义设计器改进，从 .NET Framework 移植了 ToolStripCollectionEditor 等 UITypeEditor 类型，并改进了 NVDA 屏幕阅读器支持<sup>[12](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/whats-new/net100)</sup>。

## 当前状态与今日使用

WinForms 在 GitHub 上 dotnet 组织下以 MIT 许可证公开开发，供应商分析称其随 .NET 10 的发展势头强劲<sup>[1](https://github.com/dotnet/winforms/)</sup><sup> • </sup><sup>[7](https://developer.mescius.com/blogs/winui-vs-wpf-winforms-uwp-and-mfc)</sup>。这与该框架长期以来的遗留定位并存：2006 年 WPF 推出后，微软的宣传将 WPF 定位为未来、WinForms 定位为遗留<sup>[8](https://docs.lextudio.com/blog/a-brief-history-of-net-core-winforms-designer/)</sup>。两种描述在不同层面上都是准确的：该框架在其既定范围内获得积极维护和新功能，而项目的非目标则有意将雄心勃勃的现代 UI 工作引向 WPF 或 WinUI<sup>[1](https://github.com/dotnet/winforms/)</sup>。

其实际用户是 Windows 桌面应用程序开发者，其中有相当数量的 Visual Basic .NET 使用者，其典型产品正是该框架 2002 年设计时所针对的窗体和控件业务应用程序<sup>[1](https://github.com/dotnet/winforms/)</sup>。为 .NET 重构的旧 Windows Forms 代码减少了绘制窗体和控件的内存分配，使升级后的应用程序更快<sup>[6](https://raw.githubusercontent.com/dotnet-architecture/eBooks/main/current/modernize-desktop-apps/Modernize-Desktop-Apps-on-Windows-with-NET.pdf)</sup>。

## References

1. [dotnet/winforms, GitHub repository](https://github.com/dotnet/winforms/)
2. [Desktop Guide (Windows Forms .NET), Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/overview/?view=netdesktop-9.0)
3. [Windows Forms Programming in C#, InformIT](https://www.informit.com/store/windows-forms-programming-in-c-sharp-9780321116208)
4. [Microsoft Open Sources .NET Desktop Tech: WPF, Windows Forms, WinUI, Visual Studio Magazine](https://visualstudiomagazine.com/articles/2018/12/04/net-open-source.aspx)
5. [Announcing WPF, WinForms, and WinUI are going Open Source, Scott Hanselman](https://www.hanselman.com/blog/announcing-wpf-winforms-and-winui-are-going-open-source)
6. [Modernize Desktop Apps on Windows with .NET, Microsoft architecture e-book](https://raw.githubusercontent.com/dotnet-architecture/eBooks/main/current/modernize-desktop-apps/Modernize-Desktop-Apps-on-Windows-with-NET.pdf)
7. [WinUI vs WPF, WinForms, and UWP, Mescius ComponentOne](https://developer.mescius.com/blogs/winui-vs-wpf-winforms-uwp-and-mfc)
8. [A Brief History of .NET Core WinForms Designer, Lextudio](https://docs.lextudio.com/blog/a-brief-history-of-net-core-winforms-designer/)
9. [What's new in Windows Forms runtime in .NET 5.0, .NET Blog](https://devblogs.microsoft.com/dotnet/whats-new-in-windows-forms-runtime-in-net-5-0/)
10. [What's new in Windows Forms in .NET 7.0, .NET Blog](https://devblogs.microsoft.com/dotnet/winforms-enhancements-in-dotnet-7/)
11. [Improve allocations in WinForms startup, dotnet/corefx pull request 39275](https://github.com/dotnet/corefx/pull/39275)
12. [What's new in Windows Forms for .NET 10, Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/whats-new/net100)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Graphics and multimedia APIs

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/windows-forms

English original: https://www.edgepedia.org/windows-forms
