I created a console application, but I want to turn it into a windows forms application.
I found This and it appeared to be what I needed, but I got an error message when I tried to use using System.Windows.Forms;
This is the error message I got:
Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
Is there another step, or is it somehow different in VS 2008?
A Windows form application is an application that has a graphical user interface(GUI) like the Visual C# IDE. A console program on the other hand is a text application. There are not fancy controls like buttons or textboxes in a console application and they are run from the command prompt.
You need to add a reference to the WinForms assembly
You may need to do the same for System.Data as well depending on your project setup
Make sure you add the System.Windows.Forms assembly in your references for the project. In the solution explorer, right click on 'References' and then under the .NET tab find the System.Windows.Forms assembly and add it.
You need to add a reference to System.Windows.Forms
. Right-click your project and choose Add Reference.
On the .NET tab choose the the previously mentioned reference.
The easiest way:
Starting with .Net Core 3 the easiest way to do it is to backup your Program.cs
somewhere on a disk (or just using git) and run the following command where Program.cs
is located:
dotnet new winforms --force
It will replace your Program.cs
and .csproj
. Then just copy required code from your old Program.cs
. That's it!
For manually converting the project this may be helpful:
Here is how .Net Core 3 project looks like (generated using dotnet new winforms
):
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
Here is how Program.cs
looks for a new project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LinkInterceptor
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With