This article needs to beupdated. Please help update this article to reflect recent events or newly available information.(January 2023) |
| Windows Forms (WinForms) | |
|---|---|
![]() | |
| Other names | WinForms |
| Original authors | .NET:Microsoft, Mono:Ximian/Novell |
| Developer | .NET Foundation |
| Initial release | February 13, 2002; 23 years ago (2002-02-13) |
| Stable release | |
| Repository | |
| Written in | C# |
| Operating system | Microsoft Windows |
| Platform | .NET Framework,.NET,Mono |
| Type | Software framework,widget toolkit |
| License | MIT License |
| Website | learn |
Windows Forms, also known asWinForms, is a free, open-source graphical user interface (GUI) class library for building Windows desktop applications, included as a part ofMicrosoft.NET,.NET Framework orMono,[2] providing a platform to write client applications for desktop, laptop, and tablet PCs.[3] While it is seen as a replacement for the earlier and more complexC++ basedMicrosoft Foundation Class Library, it does not offer a comparable paradigm[4] and only acts as a platform for the user interface tier in amulti-tier solution.[5]
At theMicrosoft Connect event on December 4, 2018,Microsoft announced releasing Windows Forms as an open source project onGitHub. It is released under theMIT License. With this release, Windows Forms has become available for projects targeting the.NET Core framework. However, the framework is still available only on the Windows platform, andMono's incomplete implementation of Windows Forms remains the only cross-platform implementation.[6][7]

AWindows Forms application is anevent-driven application supported by Microsoft's.NET Framework. Unlike abatch program, it spends most of its time simply waiting for the user to do something, such as fill in atext box or click abutton. The code for the application can be written in a .NET programming language such asC# orVisual Basic.
Windows Forms provides access to nativeWindows User Interface Common Controls by wrapping the existentWindows API inmanaged code.[8] With the help of Windows Forms, the .NET Framework provides a more comprehensive abstraction above the Win32 API than Visual Basic or MFC did.[9]
Windows Forms is similar toMicrosoft Foundation Class (MFC) library in developing client applications. It provides a wrapper consisting of a set of C++ classes for development of Windows applications. However, it does not provide a default application framework like the MFC. Every control in a Windows Forms application is a concrete instance of a class.
All visual elements in the Windows Forms class library derive from the Control class. This provides the minimal functionality of a user interface element such as location, size, color, font, text, as well as common events like click and drag/drop. The Control class also has docking support to let a control rearrange its position under its parent. TheMicrosoft Active Accessibility support in the Control class also helps impaired users to use Windows Forms better.[10]
In Visual Studio, forms are created usingdrag-and-drop techniques. A tool is used to place controls (e.g., text boxes, buttons, etc.) on the form (window). Controls haveattributes andevent handlers associated with them. Default values are provided when the control is created, but may be changed by the programmer. Many attribute values can be modified during run time based on user actions or changes in the environment, providing a dynamic application. For example, code can be inserted into the form resize event handler to reposition a control so that it remains centered on the form, expands to fill up the form, etc. By inserting code into the event handler for a keypress in a text box, the program can automatically translate the case of the text being entered, or even prevent certain characters from being inserted.
Besides providing access to native Windows controls like button, textbox, checkbox and listview, Windows Forms added its own controls forActiveX hosting, layout arrangement, validation and rich data binding. Those controls are rendered usingGDI+.[10]
Just likeAbstract Window Toolkit (AWT), the equivalentJava API, Windows Forms was an early and easy way to providegraphical user interface components to the.NET Framework. Windows Forms is built on the existing Windows API and some controls merely wrap underlying Windows components.[11] Some of the methods allow direct access to Win32callbacks, which are not available in non-Windows platforms.[11]
In .NET Framework 2.0, Windows Forms gained richer layout controls, Office 2003 style toolstrip controls, multithreading component, richer design-time and data binding support as well asClickOnce for web-based deployment.[12][13]
With the release of .NET Framework 3.0, Microsoft released a second, parallel API for rendering GUIs:Windows Presentation Foundation (WPF) based on DirectX,[14] together with a GUI declarative language calledXAML.[15]
During a question-and-answer session at theBuild 2014 Conference, Microsoft explained that Windows Forms was under maintenance mode, with no new features being added, but bugs found would still be fixed.[16] Most recently, improved high-DPI support for various Windows Forms controls was introduced in updates to .NET Framework version 4.5.[17]
For future development, Microsoft has succeeded Windows Forms with aXAML-based GUI entry using frameworks such asWPF andUWP. However, drag and drop placement of GUI components in a manner similar to Windows Forms is still provided in XAML by replacing the root XAML element of the Page/Window with a "Canvas" UI-Control. When making this change, the user can build a window in a similar fashion as in Windows Forms by directly dragging and dropping components using the Visual Studio GUI.
While XAML provides drag and drop placement backwards compatibility through the Canvas Control, XAML Controls are only similar to Windows Forms Controls and are not one-to-one backwards compatible. They perform similar functions and have a similar appearance, but the properties and methods are different enough to require remapping from one API to another.
Mono is a project led byXamarin (formerly byXimian, thenNovell) to create anEcma standard compliant.NET Framework compatible set of tools. In 2011,Mono's support for System.Windows.Forms as of.NET 2.0 was announced as complete;[18]System.Windows.Forms 2.0 works natively on Mac OS X.[19]However, System.Windows.Forms has not been actively developed on Mono.[20]Full compatibility with .NET was not possible, because Microsoft's System.Windows Forms is mainly a wrapper around theWindows API, and some of the methods allow direct access to Win32callbacks, which are not available in platforms other than Windows.[11] Mono's WinForms implementation is based on Mono's libgdiplus, which implementsGDI+ on top ofGtk andPango.[21]
A more significant problem is that, since version 5.2,[22]Mono has been upgraded so that its default is to assume a 64 bit platform.However, System.Windows.Forms on Mono for the Macintosh OS X platform has been built using a 32 bit subsystem,Carbon.[23]As of this date[when?], a 64-bit version of System.Windows.Forms for use on Mac OS X remains unavailable and only .NET applications built for the 32 bit platform can be expected to execute.
It is very unlikely that the implementation will ever implement everything needed for full compatibility with Windows.Forms. The reason is that Windows.Forms is not a complete toolkit, and to work around this problem some of the underlying Win32 foundation is exposed to the programmer in the form of exposing the Windows message handler
WPF is not intended to replace Windows Forms. [...] Windows Forms is still alive and well, and will continue to be enhanced and supported by Microsoft for years to come. WPF is simply another tool for Windows desktop application developers to use, when appropriate.
Windows Forms is continuing to be supported, but in maintenance mode. They will fix bugs as they are discovered, but new functionality is off the table
Support for Windows Forms 2.0 is complete. At this point, we are largely just fixing bugs and polishing our code.
Does Winforms run on OSX? Yes, as of Mono 1.9, Winforms has a native OSX driver that it uses by default
For tools that are mostly OpenGL/DirectX based, use Windows.Forms, keeping in mind that some bug fixing or work around on their part might be needed as our Windows.Forms is not actively developed.