$ show dotnet/winforms
This repository is the official .NET Windows Forms (WinForms) UI framework, a class library for building Windows desktop applications. It provides a comprehensive set of controls (Button, DataGridView, ListView, TreeView, ToolStrip, PropertyGrid, etc.), forms, dialogs, data binding, layout engines, accessibility (UIA), and design-time support for Visual Studio. The architecture is modular, with core assemblies: System.Windows.Forms (controls and forms), System.Drawing.Common (GDI+ wrappers), System.Windows.Forms.Design (designer infrastructure), System.Private.Windows.Core (low-level interop, binary format serialization, OLE), and System.Windows.Forms.Primitives (handle wrappers, GDI caches). Key entry points include Application.Run(), Form class constructors, and control instantiation. Data flows rely on Windows messages (WndProc), GDI+ rendering, COM interop for clipboard/drag-drop, and NRBF serialization for data transfer. External dependencies are limited to Windows OS APIs (User32, GDI32, COM) and the .NET runtime. The codebase is actively maintained, with ongoing modernization (e.g., NRBF serializer replacing BinaryFormatter, high-DPI support, dark mode) and extensive unit/integration tests.
The LLM identified 3 files worth highlighting for reuse:
Generic handle wrapper pattern (IHandle<THandle>) that encapsulates native handles (HWND, HDC, HICON, etc.) and uses GC.KeepAlive to prevent premature garbage collection of the owning object. This pattern is used extensively in P/Invoke extension methods to safely pass handles to native APIs. It is self-contained, demonstrates deep understanding of .NET interop and GC behavior, and can be extracted for any project that needs safe native handle management.
A discriminated union struct using explicit layout (FieldOffset) to efficiently store various types (int, float, DateTimeOffset, Color, etc.) in a single 8-byte value. It uses type flags to distinguish the stored type and provides packed representations for common types (e.g., PackedColorFlag). This is a high-performance alternative to boxing or object wrappers, and is reusable in any .NET project requiring compact, type-safe storage of heterogeneous values.
A ref struct that implements RAII for GDI device context state management. It saves and restores the state of a GDI DC (via SaveDC/RestoreDC) in a using block, ensuring proper cleanup even on exceptions. This is part of a family of similar scopes (SelectObjectScope, SetTextColorScope, SetBkModeScope, etc.) that provide safe, composable wrappers for GDI operations. The pattern is self-contained, demonstrates advanced use of ref structs and IDisposable, and can be extracted for any project that interacts with GDI.