【问题标题】:how to add icon to application's shortcut in desktop如何在桌面的应用程序快捷方式中添加图标
【发布时间】:2015-10-06 23:12:03
【问题描述】:

我希望当用户运行我的 c# 应用程序时,该应用程序将创建一个桌面快捷方式来运行应用程序。我使用此代码:

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");
}

此代码创建快捷方式,但我想将 myicon.ico 用于快捷方式图标。 我该怎么做?

【问题讨论】:

  • 我看到了,这对我有帮助!
  • 用writer.WriteLine("IconFile=" + pathToMyIconDotIco);替换writer.WriteLine("IconFile=" + icon);
  • @DavidArno 错误:名称 'pathToMyIconDotIco' 在当前上下文中不存在 c:\users\soheil\documents\visual studio 2012\Projects\shortcut\shortcut\Form1.cs
  • 当然不是。你必须创造它! :) 抱歉,如果不清楚。这是您的myicon.ico 文件的路径。

标签: c# winforms icons shortcut


【解决方案1】:

您可以使用以下步骤:

  1. 在Solution Explorer中右键单击您的项目,然后选择Properties。
  2. 应用程序标签
  3. 图标和清单
  4. 选择图标

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2023-03-18
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多