Click here to Skip to main content
15,441,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
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.
Posted
Updated 23-Apr-21 19:02pm
Comments
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
 
Comments
BillWoodruff 23-Apr-21 17:59pm     CRLF
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     CRLF
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     CRLF
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: https://stackoverflow.com/questions/4362111/how-do-i-show-a-console-output-window-in-a-forms-application
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    
lol
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
 
Comments
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     CRLF
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 https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview
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
 
v2
Comments
PIEBALDconsult 24-Apr-21 1:09am     CRLF
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     CRLF
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: https://stackoverflow.com/questions/4362111/how-do-i-show-a-console-output-window-in-a-forms-application
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
 
Comments
Richard MacCutchan 24-Apr-21 5:30am    
Yes, but as OG mentioned to Bill above, you know what you are doing.

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