how to add icon to application's shortcut in d

2020-04-15 20:01发布

问题:

I want when user runs my c# application , the application will create a desktop shortcut to run application. I use this code :

private void appShortcutToDesktop(string linkName)
{
    string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

    using (StreamWriter writer = new StreamWriter(deskDir + "\\" + linkName + ".url"))
    {
        string app = System.Reflection.Assembly.GetExecutingAssembly().Location;
        writer.WriteLine("[InternetShortcut]");
        writer.WriteLine("URL=file:///" + app);
        writer.WriteLine("IconIndex=0");
        string icon = app.Replace('\\', '/');
        writer.WriteLine("IconFile=" + icon);
        writer.Flush();
    }
}

private void button1_Click(object sender, EventArgs e)
{
    appShortcutToDesktop("MyName");
}

This code creates shortcut but I want to put myicon.ico for shortcuts icon . how can I do this ?

回答1:

You can use the following steps:

  1. Right click on your project in the Solution Explorer and select Properties.
  2. Application tab
  3. Icon and manifest
  4. Select icon