打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
图标提取以及图标转换
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);
        }
    }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C#图像处理(各种旋转、改变大小、柔化、锐化、雾化、底片、浮雕、黑白、滤镜效果)
数字图像处理 C# 程序代码实例
VA18.2 数据流概述
用IrisSkin2.dll美化你的WinForm - 夏天的风的日志 - 网易博客
C# winfrom调用摄像头扫描二维码(完整版)
C# GDI 使用操作、入门解析
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服