Skip to content

Instantly share code, notes, and snippets.

@acid-chicken
Created April 8, 2017 04:07
Show Gist options
  • Save acid-chicken/eb58d7ac7b77cd1409d8f07caf2efe0e to your computer and use it in GitHub Desktop.
Save acid-chicken/eb58d7ac7b77cd1409d8f07caf2efe0e to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ImageLoad
{
public partial class MainForm : Form
{
Bitmap[] bitmaps;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
IEnumerable<FileInfo> resources = new DirectoryInfo("Resources").EnumerateFiles("*.png", SearchOption.AllDirectories);
listView.Items.AddRange(resources.Select(selector => new ListViewItem(selector.Name)).ToArray());
bitmaps = new Bitmap[resources.Count()];
Parallel.ForEach(resources.Select((file, index) => new { file, index }), item => bitmaps[item.index] = new Bitmap(item.file.OpenRead())/*.Clone(new Rectangle(0, 0, 16, 16), PixelFormat.Canonical)*/);
}
private void listView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.Graphics.DrawImageUnscaledAndClipped(bitmaps[e.ItemIndex], e.Bounds);
if (e.State.HasFlag(ListViewItemStates.Selected)) Text = e.Item.Text;
else if (e.State.HasFlag(ListViewItemStates.Focused)) Text = "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment