Created
April 8, 2017 05:21
-
-
Save acid-chicken/5dc8b79644ce50074d7bf63bd7fbe051 to your computer and use it in GitHub Desktop.
ImageLoad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ""; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace ImageLoad | |
{ | |
partial class MainForm | |
{ | |
/// <summary> | |
/// 必要なデザイナー変数です。 | |
/// </summary> | |
private System.ComponentModel.IContainer components = null; | |
/// <summary> | |
/// 使用中のリソースをすべてクリーンアップします。 | |
/// </summary> | |
/// <param name="disposing">マネージ リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param> | |
protected override void Dispose(bool disposing) | |
{ | |
if (disposing && (components != null)) | |
{ | |
components.Dispose(); | |
} | |
base.Dispose(disposing); | |
} | |
#region Windows フォーム デザイナーで生成されたコード | |
/// <summary> | |
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を | |
/// コード エディターで変更しないでください。 | |
/// </summary> | |
private void InitializeComponent() | |
{ | |
this.listView = new System.Windows.Forms.ListView(); | |
this.SuspendLayout(); | |
// | |
// listView | |
// | |
this.listView.Dock = System.Windows.Forms.DockStyle.Fill; | |
this.listView.Location = new System.Drawing.Point(0, 0); | |
this.listView.Name = "listView"; | |
this.listView.OwnerDraw = true; | |
this.listView.Size = new System.Drawing.Size(284, 261); | |
this.listView.TabIndex = 0; | |
this.listView.TileSize = new System.Drawing.Size(20, 18); | |
this.listView.UseCompatibleStateImageBehavior = false; | |
this.listView.View = System.Windows.Forms.View.Tile; | |
this.listView.DrawItem += new System.Windows.Forms.DrawListViewItemEventHandler(this.listView_DrawItem); | |
// | |
// MainForm | |
// | |
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); | |
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; | |
this.ClientSize = new System.Drawing.Size(284, 261); | |
this.Controls.Add(this.listView); | |
this.Name = "MainForm"; | |
this.Load += new System.EventHandler(this.MainForm_Load); | |
this.ResumeLayout(false); | |
} | |
#endregion | |
private System.Windows.Forms.ListView listView; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows.Forms; | |
namespace ImageLoad | |
{ | |
static class Program | |
{ | |
/// <summary> | |
/// アプリケーションのメイン エントリ ポイントです。 | |
/// </summary> | |
[STAThread] | |
static void Main() | |
{ | |
Application.EnableVisualStyles(); | |
Application.SetCompatibleTextRenderingDefault(false); | |
Application.Run(new MainForm()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment