1

I'm new to C# & got requirement like

need to change the default console application icon programmatically [also is it possible to change during compile time].

I tried with Project -> Properties -> Application -> Icon of my solution in Visual Studio & its working fine.

Also able to set Form icon with the following code

this.Icon = new System.Drawing.Icon(@"Icon.png");

but the thing is i need to change the icon via code.

Help me out.

saravana
  • 544
  • 1
  • 7
  • 26
  • With a lot of messing about – TheGeneral Oct 26 '18 at 06:21
  • What happens when you run this code `this.Icon = new System.Drawing.Icon(@"Icon.png");`? – Chetan Oct 26 '18 at 06:21
  • @ChetanRanpariya and what exactly would "this" be in a console app? The startup is a static function. Anyway, flagged as dupe; the question TheGeneral linked has the answer, for console apps. – Nyerguds Oct 26 '18 at 06:43
  • @TheGeneral, i tried with that too but no luck. – saravana Oct 26 '18 at 06:52
  • @saravana are you trying to change the icon on the console window, or on a form launched from a console app? Because that last piece you put there _is_ programming code you can execute at any moment to change the form icon. – Nyerguds Oct 26 '18 at 07:43
  • @Nyerguds I need to change the icon of the console window – saravana Oct 26 '18 at 09:33

1 Answers1

0

I found this answer which written by Jon Skeet

You can't specify an executable's icon in code - it's part of the binary file itself.

From the command line, you'd use /win32icon:<file> if that's any help, but you can't specify it within the code of the application. Don't forget that most of the time the application's icon is displayed, your app isn't running at all!

That's assuming you mean the icon for the file itself in explorer. If you mean the icon of the application while it's running if you just double-click the file, I believe that will always just be the icon for the console itself.

Anas Alweish
  • 2,818
  • 4
  • 30
  • 44