I can't use notifyIcon on my c# console app
I am trying to make a notifyIcon by i have this: The type or namespace name 'NotifyIcon' could not be found (are you missing a using directive or an assembly reference?) and when i try to fix it using: using System.Windows.Forms; i have this error : The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
23 Replies
I tryed dotnet add package System.Windows.Forms but it didn't work
i am using vscode
and dotnet 8
Yeah iirc it's not trivial to get s notification icon with a console app, as you need a window handle to.. handle clicks on the icon.
actually i just want a tray icon
not even a console app, or any window
You can't "just" have a tray icon. They are not standalone things.
You need an application that owns the icon and handles interactions with the icon
I don't any window if you prefer
this is why i chose console app
A reasonable assumption, but a console app doesn't by default come with a window handle. And you need a window handle to have a tray icon.
If you Google ".net tray icon console app" I'm sure you'll find plenty of ways to solve this
they are using System.Windows.Forms
but i can't manage to make it works
Are they somewhat recent? Like .net 5 or newer?
A guide using .net framework will likely not work
no
I can't find something for .net 8
.net 8 is one month old bruh
do you have any idea how can add windw.Forms package to this project ?
You need to add a property to your csproj to include the winforms stuff, but I'm not sure that's enough here
How would u recommend me to do this little project ?
I wanna change the tray icon if cap is activated
Cap?
when you write in CAPITALIZE or not
Caps lock
and shift
Idk, without any research what so ever... I'd probably just make a winforms app and hide the window
That gives you a window handle and it's then trivial to implement the icon
I lookedd at that but didn't find how to hide the window
Isn't it just setting
Visible
to false on the form?wdym ?
I mean exactly that :p
a
Form
object has a Visible
property, that can be set to false. this hides the window
at least, thats what I remember. Maybe thats for controls in general and forms need to use .Hide();
not sure
winforms isnt exactly relevant these daysI finaly mange to make it, but I have an issue
This works, but I can't hide the console app
I tryed to set the output from console app to windows applcation but when I do that i don't have a tray icon
So i try to hide the windw but it just minimised it