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.Button Command3;
		public System.Windows.Forms.TextBox Text1;
		public System.Windows.Forms.Button Command2;
		public System.Windows.Forms.Button Command1;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.TextBox Text2;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit1;
		private AxIMAGEKIT7THUMBLib.AxImageKitThumb ImageKitThumb1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		//declare some variables...
		private short LastImage;
		//this array will store the filenames of the thumbnail images...
		private string[] ImageName = new string[20];

		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.Command3 = new System.Windows.Forms.Button();
			this.Text1 = new System.Windows.Forms.TextBox();
			this.Command2 = new System.Windows.Forms.Button();
			this.Command1 = new System.Windows.Forms.Button();
			this.Label1 = new System.Windows.Forms.Label();
			this.Text2 = 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();
			// 
			// Command3
			// 
			this.Command3.BackColor = System.Drawing.SystemColors.Control;
			this.Command3.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command3.Location = new System.Drawing.Point(464, 320);
			this.Command3.Name = "Command3";
			this.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command3.Size = new System.Drawing.Size(104, 33);
			this.Command3.TabIndex = 9;
			this.Command3.Text = "Get Image by Image Number";
			this.Command3.Click += new System.EventHandler(this.Command3_Click);
			// 
			// Text1
			// 
			this.Text1.AcceptsReturn = true;
			this.Text1.AutoSize = false;
			this.Text1.BackColor = System.Drawing.SystemColors.Window;
			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.SystemColors.WindowText;
			this.Text1.Location = new System.Drawing.Point(408, 320);
			this.Text1.MaxLength = 0;
			this.Text1.Name = "Text1";
			this.Text1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Text1.Size = new System.Drawing.Size(41, 25);
			this.Text1.TabIndex = 8;
			this.Text1.Text = "6";
			// 
			// Command2
			// 
			this.Command2.BackColor = System.Drawing.SystemColors.Control;
			this.Command2.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command2.Location = new System.Drawing.Point(472, 368);
			this.Command2.Name = "Command2";
			this.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command2.Size = new System.Drawing.Size(96, 33);
			this.Command2.TabIndex = 6;
			this.Command2.Text = "Get Last Image";
			this.Command2.Click += new System.EventHandler(this.Command2_Click);
			// 
			// Command1
			// 
			this.Command1.BackColor = System.Drawing.SystemColors.Control;
			this.Command1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command1.Location = new System.Drawing.Point(328, 368);
			this.Command1.Name = "Command1";
			this.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command1.Size = new System.Drawing.Size(96, 33);
			this.Command1.TabIndex = 5;
			this.Command1.Text = "Get First Image";
			this.Command1.Click += new System.EventHandler(this.Command1_Click);
			// 
			// Label1
			// 
			this.Label1.BackColor = System.Drawing.SystemColors.Control;
			this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label1.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label1.Location = new System.Drawing.Point(328, 320);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(73, 25);
			this.Label1.TabIndex = 7;
			this.Label1.Text = "Image No:";
			// 
			// Text2
			// 
			this.Text2.AcceptsReturn = true;
			this.Text2.AutoSize = false;
			this.Text2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
			this.Text2.Cursor = System.Windows.Forms.Cursors.IBeam;
			this.Text2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Text2.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
			this.Text2.Location = new System.Drawing.Point(8, 0);
			this.Text2.MaxLength = 0;
			this.Text2.Multiline = true;
			this.Text2.Name = "Text2";
			this.Text2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Text2.Size = new System.Drawing.Size(561, 49);
			this.Text2.TabIndex = 10;
			this.Text2.Text = @"Thumbnail images can be selected by clicking them with the mouse or by specifying their image number. This sample shows how to scroll the thumbnail control to display the thumbnail image that has been selected. The image is then displayed in 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(313, 337);
			this.ImageKit1.TabIndex = 11;
			// 
			// ImageKitThumb1
			// 
			this.ImageKitThumb1.Location = new System.Drawing.Point(328, 56);
			this.ImageKitThumb1.Name = "ImageKitThumb1";
			this.ImageKitThumb1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKitThumb1.OcxState")));
			this.ImageKitThumb1.Size = new System.Drawing.Size(241, 249);
			this.ImageKitThumb1.TabIndex = 12;
			this.ImageKitThumb1.ShowThumbImage += new AxIMAGEKIT7THUMBLib._IImageKitThumbEvents_ShowThumbImageEventHandler(this.ImageKitThumb1_ShowThumbImage);
			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(575, 412);
			this.Controls.Add(this.ImageKitThumb1);
			this.Controls.Add(this.ImageKit1);
			this.Controls.Add(this.Text2);
			this.Controls.Add(this.Command3);
			this.Controls.Add(this.Text1);
			this.Controls.Add(this.Command2);
			this.Controls.Add(this.Command1);
			this.Controls.Add(this.Label1);
			this.Name = "Form1";
			this.Text = "Select a Thumbnail and Scroll ";
			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 Command1_Click(object sender, System.EventArgs e)
		{
			//Scroll to and Select the first thumbnail image...
		
			//set the scroll direction...
			ImageKitThumb1.ScrollVH = IMAGEKIT7THUMBLib.ThumbnailScrollConstants.ikThumbVertical;
		
			//determine how far to scroll...
			int TopLeftImageNo;
			int scrolllength;
		
			//the StartNum property returns the image number of the
			//thumbnail currently displayed in the top left corner of the thumbnail control.
			//by subtracting the image number of the first thumbnail image, in this case 1,
			//from the StartNum and then dividing by the number of images in each row,
			//we can calculate how many rows we need to scroll in a negative directin to reach
			//the start image.
		
			//the StartNum property starts from 0 whereas the
			//imagenumber retrieved elsewhere start from 1. We need to equate the two imagenumbers...
			TopLeftImageNo =ImageKitThumb1.StartNum + 1;
		
			scrolllength = (int)((TopLeftImageNo - 1) * 1.0 /ImageKitThumb1.RowCount);
		
			//set the scrollstep (in a negative direction)...
			ImageKitThumb1.ScrollStep = (short)(-1 * scrolllength);
		
			//scroll...
			ImageKitThumb1.Scroll();
		
			//select the first thumbnail image...
			ImageKitThumb1.SelectImage(1);
		}

		private void Command2_Click(object sender, System.EventArgs e)
		{
			int TopLeftImageNo;
			//Scroll to and Select the last thumbnail image...
		
			//set the scroll direction...
			ImageKitThumb1.ScrollVH = IMAGEKIT7THUMBLib.ThumbnailScrollConstants.ikThumbVertical;
		
			//determine how far to scroll...
			short scrolllength;
		
			//the StartNum property returns the image number of the
			//thumbnail currently displayed in the top left corner of the thumbnail control.
			//by subtracting the StartNum from the image number of the last thumbnail image//
			//and then dividing by the number of images in each row,
			//we can calculate how many rows we need to sroll in a positive directin to reach
			//the last image.
		
			//the StartNum property starts from 0 whereas the
			//imagenumber retrieved elsewhere start from 1. We need to equate the two imagenumbers...
			TopLeftImageNo = ImageKitThumb1.StartNum + 1;
		
			scrolllength = (short)((LastImage - TopLeftImageNo) * 1.0 / ImageKitThumb1.RowCount);
		
			//set the scrollstep...
			ImageKitThumb1.ScrollStep = scrolllength;
		
			//scroll...
			ImageKitThumb1.Scroll();
		
			//select the last thumbnail image...
			ImageKitThumb1.SelectImage(LastImage);	//see the ShowThumbImage event...
		}

		private void Command3_Click(object sender, System.EventArgs e)
		{
			int TopLeftImageNo;
			//Scroll to and Select the thumbnail image specified in the textbox...
		
			//set the scroll direction...
			ImageKitThumb1.ScrollVH = IMAGEKIT7THUMBLib.ThumbnailScrollConstants.ikThumbVertical;
		
			//determine how far to scroll...
			short scrolllength;
		
			//the StartNum property returns the image number of the
			//thumbnail currently displayed in the top left corner of the thumbnail control.
			//by finding the difference between the StartNum and the image number of the
			//thumbnail image we want to scroll to, and then dividing by the number of
			//images in each row, we can calculate how many rows we need to scroll to
			//reach the image.
		
			//if the startnum is greater than the image number then we need to scroll in a
			//negative direction...
		
			//the StartNum property starts from 0 whereas the
			//imagenumber retrieved elsewhere start from 1. We need to equate the two imagenumbers...
			TopLeftImageNo = ImageKitThumb1.StartNum + 1;
		
			if (TopLeftImageNo > Convert.ToInt32(Text1.Text))
			{
				//the image to scroll to is currently not displayed in the thumbnail control.
				//we must scroll a minimum of 1 step
				scrolllength = (short)(-1 * ((TopLeftImageNo - Convert.ToInt32(Text1.Text)) / ImageKitThumb1.RowCount));
				if (scrolllength == 0)
					scrolllength = -1;
			}
			else
			{
				//if the image is currently displayed but in a different row then we will not scroll...
				scrolllength = (short)((Convert.ToInt32(Text1.Text) - TopLeftImageNo) * 1.0 / ImageKitThumb1.RowCount);
				if (scrolllength < 3)
					scrolllength = 0;
			}

			//set the scrollstep...
			ImageKitThumb1.ScrollStep = scrolllength;

			//scroll...
			ImageKitThumb1.Scroll();

			//select the thumbnail image by image number...
			ImageKitThumb1.SelectImage(Convert.ToInt16(Text1.Text));
		}

		private void ImageKitThumb1_SelectFile(object sender, AxIMAGEKIT7THUMBLib._IImageKitThumbEvents_SelectFileEvent e)
		{
			//display the image whose thumbnail has been selected...
			ImageKit1.File.FileName = e.pathName + e.fileName;

			//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);
		}

		private void ImageKitThumb1_ShowThumbImage(object sender, AxIMAGEKIT7THUMBLib._IImageKitThumbEvents_ShowThumbImageEvent e)
		{
			//set the image number of the last image into a variable...
			LastImage = e.maxImage;
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//set the types of images that can be loaded into the thumbnail control...
			ImageKitThumb1.FileExt = "JPG";
			
			//set the path to the images...
			ImageKitThumb1.FilePath = Application.StartupPath + "\\..\\..\\..\\..\\..\\..\\..\\Images\\ForSamples\\Thumbnails\\";
			
			//display the images in the thumbnail control...
			ImageKitThumb1.GetFiles();
		}
	}
}
