抓取檔案的ICON程式碼 | 複製程式碼(Copy to clipboard) |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TestProject
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("shell32")]
private static extern IntPtr ExtractAssociatedIcon(IntPtr hInst, string lpIconPath, ref int lpiIcon);
private IntPtr hIcon;
public Form1()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
int iIconIndex = 0;
hIcon = ExtractAssociatedIcon(this.Handle, "D:\\123.jpg", ref iIconIndex);
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Icon icon = Icon.FromHandle(hIcon);
e.Graphics.DrawIcon(icon, 10, 10);
}
}
}
沒有留言:
張貼留言