asp.net icon extraction and icon conversion of instance code _ practical Skills

Source: Internet
Author: User

Copy Code code as follows:

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= "Application |*.dll;*.exe| all program |*.*";
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= "Picture |*.jpg;*.png;*.bmp| all program |*.*";
openfiledialog1.filter= "Picture |*.jpg;*.png;*.bmp| application |*.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 Gets the stream
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)
{
Releasing mouse capture for the current application
ReleaseCapture ();
Send a message to let the system mistakenly think you pressed the mouse over the title stop
SendMessage (int) this. handle,wm_nclbuttondown,htcaption,0);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.