Programmatically change the icon of the executable

后端 未结 3 1935
你的背包
你的背包 2020-12-15 09:33

I am developing an application called WeatherBar. Its main functionality is based on its interaction with the Windows 7 taskbar — it changes the icon depending on the weathe

3条回答
  •  误落风尘
    2020-12-15 09:44

     private void button1_Click(object sender, EventArgs e)
        {
          String path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
          String name = "test";
          Shell32.Shell shl = new Shell32.ShellClass();
          // Optional code to create the shortcut
          System.IO.StreamWriter sw = new System.IO.StreamWriter(path + @"\" + name + ".lnk", false);
          sw.Close();
          // End optional code
          Shell32.Folder dir = shl.NameSpace(path);
          Shell32.FolderItem itm = dir.Items().Item(name + ".lnk");
          Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)itm.GetLink;
          // Optional code to create the shortcut
          lnk.Path = Environment.GetFolderPath(Environment.SpecialFolder.System)
    + @"\notepad.exe";
          lnk.Description = "nobugz was here";
          lnk.Arguments = @"c:\sample.txt";
          lnk.WorkingDirectory = @"c:\";
          // End optional code
          lnk.SetIconLocation(Environment.GetFolderPath(Environment.SpecialFolder.System)
    + "cmd.exe", 1);
          lnk.Save(null);
        }
    

    This was taken from http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/9e23a82c-8bed-4b96-8b9a-4c2b6136a622/

    It may help.

提交回复
热议问题