• 指定应用程序的图标,应用程序的所有形式


    介绍 在开发一个应用程序,通常,这是一件方便的事如果所有的windows应用程序,默认情况下,相同的图标像应用程序的可执行文件。然而,如果你想这样做,你必须手动分配每个表单在Visual Studio的图标。如果可执行文件图标改变,你必须重复这个工作了。本文描述了一种技巧,如何分配应用程序的图标形式由应用程序代码。 这是用c#编写的,可以用在任何。net语言作为DLL。 最重要的代码从这里得到了提取的图标。只是稍微固定和增强。 解决方案 你所要做的是: 在Visual Studio中分配一个图标到您的项目。IconRoutines类包含在文件夹添加到您的项目,或引用IconRoutines.dll在您的项目。添加以下行每个表单构造函数在你想要设置的应用程序相同的图标,应用程序的图标:隐藏,Codethis副本。图标= Cliver.IconRoutines.HostIcon; 这将使你的应用的窗户有相同的图标像应用程序本身。这是所有。 它是如何工作的 本节是写给好奇的家伙,可以省略。 第一步是获得可执行的图标。 一些浪费时间。net图标类之后,我明白正确地提取从一个EXE文件的图标(或任何包含图标的文件)不是一个简单的事情。为什么?因为几个技巧: 图标。ExtractAssociatedIcon提取只有一小图像存储在file.Icon从一个图标。保存保存在一个16色图标格式。 这意味着从文件中提取图标的代码必须从头开始写。幸运的是,这样的代码已经完成了史蒂夫•麦克马洪,只需要一些升级。它获取一个图标的图像从一个可执行的。你可以在附件找到它来源。 第二步是创建一个图标类型对象从所获取的图像。下面的代码是: 隐藏,收缩,复制Code

    /// <spanclass="code-SummaryComment"><summary></span>
    /// Extract all icon images from the library file like .exe, .dll, etc. 
    /// <spanclass="code-SummaryComment"></summary></span>
    /// <spanclass="code-SummaryComment"><paramname="file">file where icon is extracted from</param></span>
    /// <spanclass="code-SummaryComment"><returns>extracted icon</returns></span>
    public static Icon ExtractIconFromLibrary(string file)
    {
        // .NET Icon Explorer (http://www.vbaccelerator.com/home/NET/
        //                     Utilities/Icon_Extractor/article.asp) is used here.
        Icon icon = null;
        try
        {
            vbAccelerator.Components.Win32.GroupIconResources gir = 
                  new vbAccelerator.Components.Win32.GroupIconResources(file);
            if (gir.Count < 0)
                return icon;
    
            vbAccelerator.Components.Win32.IconEx i = 
                  new vbAccelerator.Components.Win32.IconEx();
            if (gir[0].IdIsNumeric)
                i.FromLibrary(file, gir[0].Id);
            else
                i.FromLibrary(file, gir[0].Name);
    
            icon = i.GetIcon();
        }
        catch (Exception e)
        {
            throw (new Exception("Could not extract the host icon.", e));
            icon = null;
        }
        return icon;
    }
    
    /// <spanclass="code-SummaryComment"><summary></span>
    /// Icon of the hosting application.
    /// <spanclass="code-SummaryComment"></summary></span>
    public static Icon HostIcon
    {
        get
        {
            if (_HostIcon == null)
                _HostIcon = IconRoutines.ExtractIconFromLibrary(
                            Application.ExecutablePath);
            return _HostIcon;
        }
    }
    static Icon _HostIcon = null;

    现在,我们只需要分配IconRoutines。HostIcon表单的图标。 使用的代码 在附加的代码中,你可以找到: 一个项目IconRoutines包含图标的代码管理。可以编译是一个DLL并链接到您的项目;别的,IconRoutines的代码添加到您的代码。项目测试引用IconRoutines.dll和使用它。 是快乐! 本文转载于:http://www.diyabc.com/frontweb/news7220.html

  • 相关阅读:
    用户控件被添加到容器的整个处理过程
    c#项目后期生成事件命令行常用命令
    Sass 系统知识
    非 root 用户
    Linux 系统版本查看
    Docker Swarm
    Docker Compose
    Linux RocketMQ双主双从,Centos7 RocketMQ4集群(双主双从)
    Linux RocketMQ安装配置和使用,Centos7 RocketMQ4安装配置
    Springboot Logback日志使用,Springboot Logback详细配置和日志分割
  • 原文地址:https://www.cnblogs.com/Dincat/p/13467480.html
Copyright © 2020-2023  润新知