vbAccelerator - Contents of code file: ThumbnailTester\frmThumbnailTester.csusing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using vbAccelerator.Components.Shell;
namespace ThumbnailTester
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmThumbnailTester : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnPick;
private System.Windows.Forms.ImageList ilsIcons;
private System.Windows.Forms.ListView lvwThumbNails;
private System.Windows.Forms.TextBox txtFileName;
private System.Windows.Forms.Label lblFileName;
private System.Windows.Forms.Label lblThumbs;
private System.ComponentModel.IContainer components;
public frmThumbnailTester()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(frmThumbnailTester));
this.btnPick = new System.Windows.Forms.Button();
this.ilsIcons = new System.Windows.Forms.ImageList(this.components);
this.lvwThumbNails = new System.Windows.Forms.ListView();
this.txtFileName = new System.Windows.Forms.TextBox();
this.lblFileName = new System.Windows.Forms.Label();
this.lblThumbs = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnPick
//
this.btnPick.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnPick.Location = new System.Drawing.Point(512, 8);
this.btnPick.Name = "btnPick";
this.btnPick.Size = new System.Drawing.Size(24, 23);
this.btnPick.TabIndex = 0;
this.btnPick.Text = "...";
this.btnPick.Click += new System.EventHandler(this.btnPick_Click);
//
// ilsIcons
//
this.ilsIcons.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
this.ilsIcons.ImageSize = new System.Drawing.Size(100, 100);
this.ilsIcons.TransparentColor = System.Drawing.Color.Transparent;
//
// lvwThumbNails
//
this.lvwThumbNails.LargeImageList = this.ilsIcons;
this.lvwThumbNails.Location = new System.Drawing.Point(72, 40);
this.lvwThumbNails.Name = "lvwThumbNails";
this.lvwThumbNails.Size = new System.Drawing.Size(436, 412);
this.lvwThumbNails.TabIndex = 2;
//
// txtFileName
//
this.txtFileName.Location = new System.Drawing.Point(72, 12);
this.txtFileName.Name = "txtFileName";
this.txtFileName.Size = new System.Drawing.Size(436, 21);
this.txtFileName.TabIndex = 3;
this.txtFileName.Text = "";
this.txtFileName.TextChanged += new
System.EventHandler(this.txtFileName_TextChanged);
//
// lblFileName
//
this.lblFileName.Location = new System.Drawing.Point(8, 12);
this.lblFileName.Name = "lblFileName";
this.lblFileName.Size = new System.Drawing.Size(64, 23);
this.lblFileName.TabIndex = 4;
this.lblFileName.Text = "&File Name:";
//
// lblThumbs
//
this.lblThumbs.Location = new System.Drawing.Point(8, 44);
this.lblThumbs.Name = "lblThumbs";
this.lblThumbs.Size = new System.Drawing.Size(64, 32);
this.lblThumbs.TabIndex = 5;
this.lblThumbs.Text = "&Thumb Nails:";
//
// frmThumbnailTester
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(544, 458);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.lblThumbs,
this.lblFileName,
this.txtFileName,
this.lvwThumbNails,
this.btnPick});
this.Font = new System.Drawing.Font("Tahoma", 8.25F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((System.Byte)(0)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmThumbnailTester";
this.Text = "ThumbNail Extraction Tester";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmThumbnailTester());
}
private void addThumbNail(
string fileName
)
{
ThumbnailCreator t = new ThumbnailCreator();
Bitmap thumb = null;
try
{
thumb = t.GetThumbNail(fileName);
}
catch (Exception ex)
{
MessageBox.Show(
this,
String.Format("Failed to get thumbnail: {0}", ex.Message),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
if (thumb != null)
{
ilsIcons.Images.Add(thumb);
ListViewItem listItem = new ListViewItem(
fileName,
ilsIcons.Images.Count - 1
);
lvwThumbNails.Items.Add(listItem);
}
}
private void btnPick_Click(object sender, System.EventArgs e)
{
using (FolderBrowser f = new FolderBrowser())
{
f.Title = "Select a folder or file to thumbnail.";
f.FileSystemAncestorsOnly = true;
f.NewDialogStyle = true;
f.NoNewFolderButton = true;
f.ShowEditBox = true;
f.ValidateEditBox = true;
f.IncludeFiles = true;
f.InitialPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
ValidationFailedEventHandler valFailed = new
ValidationFailedEventHandler(
folderBrowser_ValidationFailed);
f.ValidationFailed += valFailed;
if (f.ShowDialog(this) == DialogResult.OK)
{
string fileName = f.SelectedPath;
txtFileName.Text = fileName;
addThumbNail(fileName);
}
f.ValidationFailed -= valFailed;
}
}
private void folderBrowser_ValidationFailed(object sender,
ValidationFailedEventArgs e)
{
if (MessageBox.Show(
this,
String.Format("The folder or file '{0}' could not be found. Choose
Retry to pick another folder or Cancel to cancel.", e.Message),
this.Text,
MessageBoxButtons.RetryCancel,
MessageBoxIcon.Warning) == DialogResult.Cancel)
{
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void txtFileName_TextChanged(object sender, System.EventArgs e)
{
}
}
}
|
|