how to add icon to application's shortcut in desktop

拜拜、爱过 提交于 2019-12-31 02:41:05

问题


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


来源:https://stackoverflow.com/questions/31472297/how-to-add-icon-to-applications-shortcut-in-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!