Visual c++ 2010 Express had a list of many installed templates, one of which was Windows Forms Application. Visual Studio 2012 express combined all the seperate languages in to one package, and now there is not an option for Windows Forms Application for C++, only for Visual Basic and C#. How can I create one?
4 Answers
The "Windows Forms" project template was (wisely) removed from the C++/CLI language. If you want to use Windows Forms, you should use C# or VB.NET.
See also: Breaking Changes in Visual C++
Quote:
The following project templates no longer exist:
- Windows Forms Application
- Windows Forms Control Library
Although we recommend that you do not create Windows Forms applications in C++/CLI, maintenance of existing C++/CLI UI applications is supported. If you have to create a Windows Forms application, or any other .NET UI application, use C# or Visual Basic. Use C++/CLI for interoperability purposes only.
In fact although it isn't suggested, it is still possible to use C++/CLI for graphical user interfaces using WinForms or even WPF. It isn't much fun because you have to write all the code yourself, no XAML support, no visual designers. But if you have a situation where the designers weren't applicable anyway (creating controls ina loop for example) then that might not be much a big disadvantage.
You can start with a console application template, instantiate a form and call Application.Run, and so on with all the other UI code. Then in the linker settings, change the subsystem from Console to Windows.
Again, this is the hard way to make .NET GUIs, and I don't suggest it. But if you want to do it anyway, that's how.
And for the intersection of GUI and native interop, for example working with OpenGL or OpenCV or Direct Show, it may be the least painful option.
I would able to create a simple Visual C++ Windows Form application using installed VS 2010 and after this I just open it in VS 2015.
And it seems like it has been converted to the last .NET Framework and C# internally.
Take a look at the picture.
Probably nowdays (year 2015) does not make sense to create Windows Form Application using Visual C++ anymore. You have to use C# or Visual Basic .NET.
The support for Windows forms with C++ has been improved since VS 2012. In VS 2019 install the workload ".net desktop development" and "C++/CLI support for v142 build tools (14.28)" under "individual components" in the VS installer. Forms can then be inserted as new items under the category GUI and they also have designer support now. Moreover, after installing the addin C++/CLR Windows forms for Visual Studio 2019 by Richard Kaiser the project template "CppCLR_WindowsFormsProject" becomes available.
Event handling can be added by clicking in the property window, the same as in C#, VB.net, basically everything works the same way. You can also create WinForms user controls with C++, I did this here (https://github.com/Jens-Kluge/Wavelet-CppWForms). Further explanations are given in the book "C++ mit Visual Studio und Windows Forms Anwendungen" by Richard Kaiser (see also https://www.rkaiser.de/wp-content/uploads/2019/04/cpp-2019-WinForms-Anleitung-EN.pdf for a tutorial). The only thing I am missing is the nuget libraries, most of them won't install for C++/CLI projects.