Click here to Skip to main content
15,795,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can I insert form in c# console app? It doesn't come up in my developer tool. I have visual studio 2019 . can I get help? thank you

What I have tried:

reload it in .net console app I tried to look up on the net, not having yet success.
Updated 4-Feb-23 0:46am
SeanChupas 23-Apr-21 14:53pm    
That's because console apps do not have forms. If you want a form, don't do a console app, do a windows forms app.
BillWoodruff 24-Apr-21 7:44am    
see my reply here.

Console apps are just that: designed for a text-based command oriented input system, with text based output - they do not support the message loop and suchlike that is required of a Windows app with forms.

Instead, you need a Windows based forms project, not a Console project.
See here: Step 1: Create a Windows Forms App project - Visual Studio | Microsoft Docs[^]
Share this answer
BillWoodruff 23-Apr-21 17:59pm    
A long time ago I did a Console app that used several WinForms for data input ... what drove this chimeric choice :) was the client's demand for the end-user to have a highly controlled experience, almost a kiosk-like ui.

Well, we all have things we'd like to forget.
OriginalGriff 24-Apr-21 0:53am    
Yes ... but you know what you are doing, and the OP clearly doesn't yet.
He'll get there, but let's not make it difficult for him, eh? :D
BillWoodruff 24-Apr-21 7:31am    
Yes, a chimeric app is not good food for this OP :)

Not the big picture: "they do not support the message loop and suchlike that is required of a Windows app with forms." There is a fix for that: adorn the Console app Main method with [STAThread]

You may find this thread interesting:
PIEBALDconsult 24-Apr-21 1:05am    
A WinForms app with a console is exactly the same as a WinForms app without a console except for that it has a console.
Richard MacCutchan 24-Apr-21 5:29am    
Hey...Here Is My Answer :
If you start a forms project in C# in Visual Studio, then make your appropriate forms, but then change the project type to a console application (by right clicking the project-->properties-->Console Application), it will still spawn your forms, but will also keep a Console open, now all you need to do is put one Console.Write statement before your form is created, and the other after, and maybe add a flush statement!

Code :
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Project1
class Class2

static void Main()
Class2 t = new Class2();
Console.WriteLine("second string");

public void test()
Thread t = new Thread(new ThreadStart(StartNewStaThrea));

private void StartNewStaThrea()
Application.Run(new Form1());


=> This Code Will Be Working For Your Work Thankyou...
Share this answer
That's because console apps do not have forms. If you want a form, don't do a console app, do a windows forms app.
Share this answer
BillWoodruff 23-Apr-21 17:53pm    
Console apps can use Windows Forms ... but, that is not good programming practice.
PIEBALDconsult 24-Apr-21 1:04am    
Sure it is, better than the normal WinForms app because it allows you to log to the console if something goes wrong during initialization or something.
SeanChupas 26-Apr-21 9:02am    
Ability to log to console should not be a deciding factor of what type of project to make.
SeanChupas 26-Apr-21 9:01am    
They can, but OP was asking why they couldn't find them in the toolbars. Because they are not there, until you go and manually put them in.
BillWoodruff 26-Apr-21 11:52am    
You are really confused, which is okay, but, how about improving your knowledge before you post on QA.

If you start a .NET FrameWork Console app, there is no way to display a WinForm in design-view, or, display a toolbar with WinForm Controls.

If you ADD a WinForm to the Project, only then do you get the design-time view.

If you start a .NET Core Console app, you cannot use Windows.Forms in any way.

The .NET Core WinForm project designer is still not in final form, and is available only for .NET Core WinForm apps. It won't work in my Visual Studio 16.9.4
Console apps can use Windows Forms; you can register/define events in the Console for publicly exposed Controls in the Form, get callbacks, etc. ... but, that is not good programming practice !

What is the reason you want to use a Form in a Console app ?
Share this answer
PIEBALDconsult 24-Apr-21 1:09am    
For me, mostly so I can have a hybrid app and control how it works via command line switches.
Maybe I want the GUI, maybe I don't, I can choose.
Pretty much all my WinForms apps have consoles.
BillWoodruff 24-Apr-21 7:22am    
Hi Piebald,

I feel strongly that newcomers to C# and WinForms should not be distracted by the complexity of chimeric apps.
Interesting ! I'd enjoy seeing an article by you on this. This SO thread was helpful back when I was doing my chimeric app:
The same as you would do with a WinForms app, I do it all the time. Granted I don't have VS 2019, but all versions I've used up to VS 2015 will do it, no problem.
Share this answer
Richard MacCutchan 24-Apr-21 5:30am    
Yes, but as OG mentioned to Bill above, you know what you are doing.
You guys should play more nicely. I have been programming many of my 74 years.

This is a valid question and no one is answering.

I am trying to learn C# and Dot Net. VS2022 has a project creation wizard named "Windows Form App C#." It creates an app in C# with one form.

Right click on project name under solution. Hover over add, and then select Form. Strange but if you select new item, Form is not included.

Does anyone know where one might find a COMPLETE reference to the files in a solution created by the wizard and how they interact. Seems even somewhat simple changes cause the solution to error?
Share this answer
Dave Kreskowiak 27-Nov-22 22:07pm    
DO NOT add your question as an answer to an old question. Go to the Quick Answers menu and click "Ask a question".

Having got that out of the way, there is no definitive list of file types you can add to a project because that list can change depending on the workloads you have configured for Visual Studio, any extensions you have installed, and any 3rd party control and project sets.

The Form item does show up in the Add -> New Item list. Just type "Form" in the Search box in the top right corner of the Add New Item dialog and "Form (Windows Forms)" will show up in the list.

Of course, all of this depends on the ".NET Desktop Development" workload being installed when you installed Visual Studio.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900