asp.net如何实现图标提取以及图标转换

发布时间:2021-10-13 09:16:33 作者:小新
来源:亿速云 阅读:88

这篇文章主要介绍了asp.net如何实现图标提取以及图标转换,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

复制代码 代码如下:


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Resources;
using System.Reflection;
using System.Runtime.InteropServices;


namespace newExtIcon
{
    public partial class MainForm : Form
    {   
        public Assembly asm = Assembly.GetExecutingAssembly();
        public MainForm()
        {
            InitializeComponent();       
        }

        void MainForm_Load(object sender ,EventArgs e)
        {
            lbl_display.Text ="No Work !";   

        }

        void btnExtractClick(object sender, EventArgs e)
        {
            Random rd = new Random();
            openFileDialog1.Filter="应用程序|*.dll;*.exe|所有程序|*.*";
            if(openFileDialog1.ShowDialog()== DialogResult.OK)
            {
                Icon icon = Icon.ExtractAssociatedIcon(openFileDialog1.FileName);
                FileStream fileStream = new FileStream("d:\\"+rd.Next(1,100000)+".ico",FileMode.Create);
                icon.Save(fileStream);
                fileStream.Close();       
                lbl_display.Text="Work Done!";
            }
            else
            {
                return ;
            }
        }

        void BtnChangeClick(object sender, EventArgs e)
        {
            Size sz = new Size(32,32);
            Random rd = new Random();
            openFileDialog1.Filter="图片|*.jpg;*.png;*.bmp|所有程序|*.*";
            //openFileDialog1.Filter="图片|*.jpg;*.png;*.bmp|应用程序|*.dll;*.exe";
            if(openFileDialog1.ShowDialog()== DialogResult.OK)
            {
                using(Bitmap bm = new Bitmap(openFileDialog1.FileName))
                {
                    using(Bitmap IconBM = new Bitmap(bm,sz))
                    {
                        using(Icon icon_t = Icon.FromHandle(IconBM.GetHicon()))
                        {
                            FileStream fileStream = new FileStream("d:\\"+rd.Next(1,100000)+".ico",FileMode.Create);
                            icon_t.Save(fileStream);
                            fileStream.Close();   
                            lbl_display.Text="Work Done!";        
                        }
                    }
                }
            }
            else
            {
                return ;
            }

        }
        void Pic_Click(object sender, System.EventArgs e)
        {
            int int_index = Convert.ToInt32(((PictureBox)sender).Tag) ;
            switch(int_index)
            {
                case 1:
                    this.Close();
                    Application.Exit();
                    break;
                case 2:
                    WindowState = FormWindowState.Minimized;
                    break;
                default :
                    break;

            }

        }

        void Pic_Hover(object sender,EventArgs e)
        {
            string  name_1 = "btn_close_hightligth.png";
            string name_2 ="btn_mini_highlight.png";
            Bitmap bm_1 = new Bitmap(asm.GetManifestResourceStream(name_1));
            Bitmap bm_2 = new Bitmap(asm.GetManifestResourceStream(name_2));
            int int_index = Convert.ToInt32(((PictureBox)sender).Tag) ;
            switch(int_index)
            {
                case 1:
                    pictureBox1.BackgroundImage=bm_1;
                    break;
                case 2:
                    pictureBox2 .BackgroundImage = bm_2;
                    break;
                default :
                    break;

            }
        }
        void Pic_Leave(object sender,EventArgs e)
        {
            string  name_1 = "btn_close_down.png";
            string  name_2 ="btn_mini_down.png";
            Bitmap bm_1 = new Bitmap(asm.GetManifestResourceStream(name_1));
            Bitmap bm_2 = new Bitmap(asm.GetManifestResourceStream(name_2));
            //GetMainfestResourceStream获取的是流
            int int_index = Convert.ToInt32(((PictureBox)sender).Tag) ;
            switch(int_index)
            {
                case 1:
                    pictureBox1.BackgroundImage=bm_1;
                    break;
                case 2:
                    pictureBox2 .BackgroundImage = bm_2;
                    break;
                default :
                    break;

            }
        }

        private const int WM_NCLBUTTONDOWN = 0xA1;
        private const int HTCAPTION = 2;

        [DllImport("user32.dll")]
        private static extern int SendMessage (int hwnd, int wMsg, int wParam, int lParam);

        [DllImport("user32.dll")]
        private static extern int ReleaseCapture();

        private void form_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            //为当前的应用程序释放鼠标捕获
            ReleaseCapture();
            //发送消息,让系统误以为你在标题拦上按下鼠标
            SendMessage((int)this.Handle,WM_NCLBUTTONDOWN,HTCAPTION,0);
        }
    }
}

感谢你能够认真阅读完这篇文章,希望小编分享的“asp.net如何实现图标提取以及图标转换”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. 8 图标 换行 以及其他
  2. 百度地图标注图标太小

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

asp.net

上一篇:如何用用导航猫Navicat简单操作你的数据库

下一篇:如何实现c++数值66,右旋,关联拉格朗日,比较审元

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》