using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Project1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		public System.Windows.Forms.TextBox Text1;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit1;
		private AxIMAGEKIT7THUMBLib.AxImageKitThumb ImageKitThumb1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.Text1 = new System.Windows.Forms.TextBox();
			this.ImageKit1 = new AxIMAGEKIT7Lib.AxImageKit();
			this.ImageKitThumb1 = new AxIMAGEKIT7THUMBLib.AxImageKitThumb();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKitThumb1)).BeginInit();
			this.SuspendLayout();
			// 
			// Text1
			// 
			this.Text1.AcceptsReturn = true;
			this.Text1.AutoSize = false;
			this.Text1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
			this.Text1.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.Text1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Text1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
			this.Text1.Location = new System.Drawing.Point(6, 0);
			this.Text1.MaxLength = 0;
			this.Text1.Multiline = true;
			this.Text1.Name = "Text1";
			this.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Text1.Size = new System.Drawing.Size(617, 49);
			this.Text1.TabIndex = 3;
			this.Text1.Text = @"The Thumbnail Control can display multipage image files too. In this sample, each page of a multipage Tiff file is displayed seperately in the Thumbnail Control. When a thumbnail image is selected, the SelectFile event returns the image path and filename along with a page index allowing that page of the multipage file to be loaded into the ImageKit Control. ";
			// 
			// ImageKit1
			// 
			this.ImageKit1.Location = new System.Drawing.Point(8, 56);
			this.ImageKit1.Name = "ImageKit1";
			this.ImageKit1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit1.OcxState")));
			this.ImageKit1.Size = new System.Drawing.Size(361, 313);
			this.ImageKit1.TabIndex = 4;
			// 
			// ImageKitThumb1
			// 
			this.ImageKitThumb1.Location = new System.Drawing.Point(376, 56);
			this.ImageKitThumb1.Name = "ImageKitThumb1";
			this.ImageKitThumb1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKitThumb1.OcxState")));
			this.ImageKitThumb1.Size = new System.Drawing.Size(249, 313);
			this.ImageKitThumb1.TabIndex = 5;
			this.ImageKitThumb1.SelectFile += new AxIMAGEKIT7THUMBLib._IImageKitThumbEvents_SelectFileEventHandler(this.ImageKitThumb1_SelectFile);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(629, 373);
			this.Controls.Add(this.ImageKitThumb1);
			this.Controls.Add(this.ImageKit1);
			this.Controls.Add(this.Text1);
			this.Name = "Form1";
			this.Text = "Multipage Files and Thumbnails";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKitThumb1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//set the types of images that can be loaded into the thumbnail control...
			ImageKitThumb1.FileExt = "TIF";
			
			//set the read mode so that multi-page images are loaded...
			ImageKitThumb1.ReadMode = IMAGEKIT7THUMBLib.ThumbnailReadModeConstants.ikThumbRdDspMultiImg;
			
			//set the path to the images...
			ImageKitThumb1.FilePath = Application.StartupPath + "\\..\\..\\..\\..\\..\\..\\..\\Images\\ForSamples\\Thumbnails\\";
			
			//display the images in the thumbnail control...
			ImageKitThumb1.GetFiles();
		}

		private void ImageKitThumb1_SelectFile(object sender, AxIMAGEKIT7THUMBLib._IImageKitThumbEvents_SelectFileEvent e)
		{
			//get the index of a multi-page image file...
			//Here we are loading only one multi-page file 
			//so the index will be the ImageNumber - 1
			short ImgIndex;

			ImgIndex = Convert.ToInt16(e.imageNumber - 1);			

			//reconstruct the filename of the multi-page image file so that there is no index number at the end...
			//If there is no index then use the value returned in the Filename argument,
			//otherwise remove the index from the value returned in the FileName argument.
			string ImgFileName;

			if (ImgIndex != 0) 
			{
				ImgFileName = e.fileName.Substring(0,e.fileName.Length-ImgIndex.ToString().Length);
			}
			else 
			{
				ImgFileName = e.fileName;
			}

			//set this index into the LoadPage property...
			ImageKit1.File.LoadPage = ImgIndex;

			//display the image whose thumbnail has been selected...
			ImageKit1.File.FileName = e.pathName + ImgFileName;

			//load the image file...
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);

			//display the image in actual sized display mode...
			ImageKit1.ScrollBar = true;
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikActualSize);
		}
	}
}
