Is it possible to change a console window's ic

2019-02-11 14:07发布

问题:

Is it possible to change a console window's icon from .net? Without using win32 calls.

回答1:

If it is your own application's console window, then you can...

  1. Double-click on "Properties" under your console project in Solution Explorer
  2. Select the option "Icon and manifest"
  3. Add your icon in that panel.

(I'm assuming you are in a C# environment, but VB.NET should be similar)

If you are starting an external process... then you can make a "launcher" console project to which you can set your own icon the same way as above.

If you mean an externally owned console window that you don't have control over... then I think you do need win32/pinvoke call.



回答2:

I had the icon set in the project properties, as Chakrit suggested, but my problem was that I was running it from Visual Studio, which runs app.vshost.exe, not app.exe directly.

Since app.vshost.exe didn't have the icon it was appearing not to work, even though it was configured correctly.



回答3:

Generally, you cannot assign an icon to the window of the application when it is running from vshost. It will work correctly when it is running outside the IDE, with the condition that you set a custom icon in the Project Properties dialog.