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
	{
		private System.Windows.Forms.TextBox textBox1;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit1;
		/// <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>
		
		short LayerNo;
		int[] RasterImageOffsetX = new int[7];
		int[] RasterImageOffsetY = new int[7];
		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.ImageKit1 = new AxIMAGEKIT7Lib.AxImageKit();
			this.textBox1 = new System.Windows.Forms.TextBox();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			this.SuspendLayout();
			// 
			// 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(528, 408);
			this.ImageKit1.TabIndex = 2;
			this.ImageKit1.MouseMoveImage += new AxIMAGEKIT7Lib._IImageKitEvents_MouseMoveImageEventHandler(this.ImageKit1_MouseMoveImage);
			this.ImageKit1.MouseDownSelectLayerImage += new AxIMAGEKIT7Lib._IImageKitEvents_MouseDownSelectLayerImageEventHandler(this.ImageKit1_MouseDownSelectLayerImage);
			this.ImageKit1.MouseUpImage += new AxIMAGEKIT7Lib._IImageKitEvents_MouseUpImageEventHandler(this.ImageKit1_MouseUpImage);
			// 
			// textBox1
			// 
			this.textBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(255)), ((System.Byte)(192)));
			this.textBox1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0)));
			this.textBox1.Location = new System.Drawing.Point(8, 0);
			this.textBox1.Multiline = true;
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(528, 48);
			this.textBox1.TabIndex = 3;
			this.textBox1.Text = @"Not only can we display multiple images simultaneously and set their positions, by using the MouseDownSelectLayerImage event in conjunction with the MouseMoveImage and MouseUpImage events we can use the mouse to select an image layer and reposition it by simply dragging it where we want it.";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(544, 470);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.ImageKit1);
			this.Name = "Form1";
			this.Text = "Moving Image Layers With Mouse";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

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

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (ImageKit1.File.OpenFileDialog() == false) 
				return;			
			
			//load the image file...
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
			
			//enable scroll bars and display image in actual size
			ImageKit1.ScrollBar = true;
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikActualSize);

		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			//set some properties for the PanWindow
			ImageKit1.PanWindow.Caption = "Pan";
			ImageKit1.PanWindow.CloseBox = true;
			ImageKit1.PanWindow.Left = 50;
			ImageKit1.PanWindow.Top = 50;
			
			//enable the pan window
			ImageKit1.PanWindow.Show(true);
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			short n;
		
			ImageKit1.ImageHandle = 0;
			for(n = 0; n <= 6; ++n)
			{
				ImageKit1.get_Layer(n).ImageHandle = 0;			
				RasterImageOffsetX[n] = 0;
				RasterImageOffsetY[n] = 0;
			}

			LoadRasterImage();
		}

		private void LoadRasterImage()
		{
			short n;
			LayerNo = -1;
			ImageKit1.File.FileName = Application.StartupPath + @"\..\..\..\..\..\..\..\Images\ForSamples\base.jpg";
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
		
			for(n = 0; n <= 6; ++n)
			{

				ImageKit1.LayerNo = n;
				ImageKit1.File.FileName = Application.StartupPath + @"\..\..\..\..\..\..\..\Images\ForSamples\" + n.ToString() + ".bmp";
				ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
			
				//ImageKit1.Layer(n).Transparent = false;
			
				ImageKit1.get_Layer(n).TransRed = 0;
				ImageKit1.get_Layer(n).TransGreen = 0;
				ImageKit1.get_Layer(n).TransBlue = 0;
			
				ImageKit1.get_Layer(n).ImageHandle = ImageKit1.CopyImage(0);
			
				ImageKit1.get_Layer(n).StartX = n * 90;
				ImageKit1.get_Layer(n).StartY = n * 65;
			}
		
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
			}

		private void ImageKit1_MouseUpImage(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseUpImageEvent e)
		{
			LayerNo = -1;
		}

		private void ImageKit1_MouseMoveImage(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseMoveImageEvent e)
		{
			if(LayerNo < 0) 
			{
				return;
			}

			ImageKit1.get_Layer(LayerNo).StartX = 0 + e.x - RasterImageOffsetX[LayerNo];
			ImageKit1.get_Layer(LayerNo).StartY = 0 + e.y - RasterImageOffsetY[LayerNo];
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
		}

		private void ImageKit1_MouseDownSelectLayerImage(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseDownSelectLayerImageEvent e)
		{
			if(e.index < 0) 
			{
				return;
			}
			LayerNo = e.index;
			RasterImageOffsetX[LayerNo] = e.x;
			RasterImageOffsetY[LayerNo] = e.y;
		}
	}
}
