❔ How do I use the System.Windows.Forms namespace in a .net core compiled console app ?
I want to use the open file dialog box and the messagebox functionalities from this namespace in my console app. the former is for selecting a path of a particular file by which my app does few file related operations and the messagebox is used for displaying success and error messageboxes.
23 Replies
you don't
if you want to use Windows GUI controls out of System.Windows.Forms, you're not making a console app, you're making a Windows Forms app
then is there any way by which I can spawn the open file dialog box to set the paths ?
or more appropriately is there a way by which I can let an user set the path of a particular file via the console ?
I mean, yeah, it's the console
you can give the user a prompt to put in a file path
if you want to use Windows components, like the dialog, you're not making a Console app, like I said
which you can do
hmm...I also have the option of going back to 4.8 framework for this as console apps made with that do support the winforms namespace but as it is ancient, I don't want to use that.
they don't
they're not console apps
so 4.8 framework compiled console apps aren't console apps ?
if they use Windows components, no
This is a snippet from one of my console apps. it does use winforms components.
https://github.com/Surihix/FFXIIIMovieAudioMod/blob/master/Core.cs
that makes it not a Console app
oh ok. thanks for helping out with this.
if you really want the dialogs, just look into making a WinForms or WPF app in
NET 5+
if you still want a console on top of that, you can do that too
It should still be possible to open a dialog window even from console. Maybe not by built-in stuff but I can imagine it's plausible through WinApi?
I have an approach which can theoretically use the winforms as well as the console too but its a bit hacky in nature
It's not supported though so yeah, it's surely hacky
my method is to basically have the open dialog thingy be a winforms app and lauch the app via the console
this would mean that I have to use multiple apps for this
probably two of them
And then return the file name from your forms app to the application which launched it?
yup. like that.
I like the idea. I know it's crazy and I know it's not the way of doing things but I like the idea of thinking outside the box. That's where all the brilliancy comes from
last option would be to use framework and make everything a single app. but framework is outdated and I don't want to use that.
I remember in the old days where wanted persistent data so I just appended it to the currently running exe file at the end, and then had a function to read that data so people could store data and read it by just passing the executable. Not a very fancy way of doing things but...hacky.
yeah sometimes we have to do such approaches according to the situation.
I still consider myself new to C# and have a lot to learn
Are you new to programming in general?
Oh nevermind, you told above
C sharp is a great language 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.