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;
		public System.Windows.Forms.Button Command1;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.Button Command2;
		public System.Windows.Forms.Button Command3;
		public System.Windows.Forms.Button Command4;
		public System.Windows.Forms.Button Command5;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private int xL1; // left image start point
		private int yL1; // left image start point
		private int xL2; // left image end point
		private int yL2; // left image end point
		private int xR1; // right image start point
		private int yR1; // right image start point
		private int xR2; // right image end point
		private int yR2;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit1;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit2;
		private AxIMAGEKIT7Lib.AxImageKit ImageKit3; // right image end point
		private int PointNum;

		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.ImageKit1 = new AxIMAGEKIT7Lib.AxImageKit();
			this.ImageKit2 = new AxIMAGEKIT7Lib.AxImageKit();
			this.ImageKit3 = new AxIMAGEKIT7Lib.AxImageKit();
			this.Text1 = new System.Windows.Forms.TextBox();
			this.Command1 = new System.Windows.Forms.Button();
			this.Label1 = new System.Windows.Forms.Label();
			this.Command2 = new System.Windows.Forms.Button();
			this.Command3 = new System.Windows.Forms.Button();
			this.Command4 = new System.Windows.Forms.Button();
			this.Command5 = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit3)).BeginInit();
			this.SuspendLayout();
			// 
			// ImageKit1
			// 
			this.ImageKit1.Location = new System.Drawing.Point(16, 56);
			this.ImageKit1.Name = "ImageKit1";
			this.ImageKit1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit1.OcxState")));
			this.ImageKit1.Size = new System.Drawing.Size(249, 185);
			this.ImageKit1.TabIndex = 0;
			this.ImageKit1.MouseDownImage += new AxIMAGEKIT7Lib._IImageKitEvents_MouseDownImageEventHandler(this.ImageKit1_MouseDownImage);
			this.ImageKit1.MouseDownEvent += new AxIMAGEKIT7Lib._IImageKitEvents_MouseDownEventHandler(this.ImageKit1_MouseDownEvent);
			// 
			// ImageKit2
			// 
			this.ImageKit2.Location = new System.Drawing.Point(304, 56);
			this.ImageKit2.Name = "ImageKit2";
			this.ImageKit2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit2.OcxState")));
			this.ImageKit2.Size = new System.Drawing.Size(249, 185);
			this.ImageKit2.TabIndex = 1;
			this.ImageKit2.MouseDownImage += new AxIMAGEKIT7Lib._IImageKitEvents_MouseDownImageEventHandler(this.ImageKit2_MouseDownImage);
			this.ImageKit2.MouseDownEvent += new AxIMAGEKIT7Lib._IImageKitEvents_MouseDownEventHandler(this.ImageKit2_MouseDownEvent);
			// 
			// ImageKit3
			// 
			this.ImageKit3.Location = new System.Drawing.Point(16, 288);
			this.ImageKit3.Name = "ImageKit3";
			this.ImageKit3.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit3.OcxState")));
			this.ImageKit3.Size = new System.Drawing.Size(433, 201);
			this.ImageKit3.TabIndex = 2;
			// 
			// 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(8, 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(561, 49);
			this.Text1.TabIndex = 10;
			this.Text1.Text = @"The Panorama method provides an easy way to attach two images into a panorama view. First load two images, one in each of the ImageKit Controls. Then set two attachment points on the left image and two attachment points on the right image. Click the Execute Button.";
			// 
			// 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(24, 248);
			this.Command1.Name = "Command1";
			this.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command1.Size = new System.Drawing.Size(105, 33);
			this.Command1.TabIndex = 11;
			this.Command1.Text = "Load Image";
			this.Command1.Click += new System.EventHandler(this.Command1_Click);
			// 
			// Label1
			// 
			this.Label1.BackColor = System.Drawing.SystemColors.Control;
			this.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
			this.Label1.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Label1.Location = new System.Drawing.Point(144, 256);
			this.Label1.Name = "Label1";
			this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Label1.Size = new System.Drawing.Size(281, 25);
			this.Label1.TabIndex = 12;
			this.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
			// 
			// 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(440, 248);
			this.Command2.Name = "Command2";
			this.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command2.Size = new System.Drawing.Size(105, 33);
			this.Command2.TabIndex = 13;
			this.Command2.Text = "Load Image";
			this.Command2.Click += new System.EventHandler(this.Command2_Click);
			// 
			// 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(472, 304);
			this.Command3.Name = "Command3";
			this.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command3.Size = new System.Drawing.Size(89, 41);
			this.Command3.TabIndex = 14;
			this.Command3.Text = "Set Attachment Location";
			this.Command3.Click += new System.EventHandler(this.Command3_Click);
			// 
			// Command4
			// 
			this.Command4.BackColor = System.Drawing.SystemColors.Control;
			this.Command4.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command4.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command4.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command4.Location = new System.Drawing.Point(472, 360);
			this.Command4.Name = "Command4";
			this.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command4.Size = new System.Drawing.Size(89, 41);
			this.Command4.TabIndex = 15;
			this.Command4.Text = "Execute";
			this.Command4.Click += new System.EventHandler(this.Command4_Click);
			// 
			// Command5
			// 
			this.Command5.BackColor = System.Drawing.SystemColors.Control;
			this.Command5.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command5.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command5.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command5.Location = new System.Drawing.Point(472, 424);
			this.Command5.Name = "Command5";
			this.Command5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command5.Size = new System.Drawing.Size(89, 41);
			this.Command5.TabIndex = 16;
			this.Command5.Text = "End";
			this.Command5.Click += new System.EventHandler(this.Command5_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(572, 496);
			this.Controls.Add(this.Command5);
			this.Controls.Add(this.Command4);
			this.Controls.Add(this.Command3);
			this.Controls.Add(this.Command2);
			this.Controls.Add(this.Label1);
			this.Controls.Add(this.Command1);
			this.Controls.Add(this.Text1);
			this.Controls.Add(this.ImageKit3);
			this.Controls.Add(this.ImageKit2);
			this.Controls.Add(this.ImageKit1);
			this.Name = "Form1";
			this.Text = "Panorama";
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit3)).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)
		{
			//display the Open file dialog
			if( ImageKit1.File.OpenFileDialog() == false)
			{
				return;
			}
		
			//load image
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
		
			//check to see if it is a raster image
			if (ImageKit1.ImageKind != IMAGEKIT7Lib.ImageKindConstants.ikRasterImage) 
			{
				ImageKit1.FreeMemory(ImageKit1.ImageHandle);
			}
		
			//display image
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
		}

		private void Command2_Click(object sender, System.EventArgs e)
		{
			//display the Open file dialog
			if( ImageKit2.File.OpenFileDialog() == false)
			{
				return;
			}
		
			//load image
			ImageKit2.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
		
			//check to see if it is a raster image
			if (ImageKit2.ImageKind != IMAGEKIT7Lib.ImageKindConstants.ikRasterImage) 
			{
				ImageKit2.FreeMemory(ImageKit1.ImageHandle);
			}
		
			//display image
			ImageKit2.Display(IMAGEKIT7Lib.DispModeConstants.ikScale);
		}

		private void Command3_Click(object sender, System.EventArgs e)
		{
			ImageKit1.CtlRefresh();
			ImageKit2.CtlRefresh();
			xL1 = 0;
			yL1 = 0;
			xL2 = 0;
			yL2 = 0;
			xR1 = 0;
			yR1 = 0;
			xR2 = 0;
			yR2 = 0;
			PointNum = 0;
			Disp();
		}

		private void Command4_Click(object sender, System.EventArgs e)
		{
			bool ret;
		
			Label1.Text = "";
		
			if (ImageKit1.ImageHandle == 0) 
			{
				MessageBox.Show("Please load an image into the ImageKit Control on the left.");
				return;
			}
			if (ImageKit2.ImageHandle == 0) 
			{
				MessageBox.Show("Please load an image into the ImageKit Control on the right.");
				return;
			}
			if (xL1 == 0) 
			{
				if (yL1 == 0) 
				{
					return;
				}
			}
			if (xL2 == 0) 
			{
				if (yL2 == 0) 
				{
					return;
				}
			}
			if (xR1 == 0) 
			{
				if (yR1 == 0) 
				{
					return;
				}
			}
			if (xR2 == 0) 
			{
				if (yR2 == 0) 
				{
					return;
				}
			}
		
			ret = ImageKit3.Effect.Panorama(ImageKit1.ImageHandle, ImageKit2.ImageHandle, 1, xL1, yL1, xL2, yL2, xR1, yR1, xR2, yR2, 255, 255, 255);
			if (ret == false) 
			{
				MessageBox.Show("Unable to create panorama");
				return;
			}
		
			ImageKit3.Display(IMAGEKIT7Lib.DispModeConstants.ikStretch);
		}

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

		private void ImageKit1_MouseDownEvent(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseDownEvent e)
		{
			bool ret;
			if (ImageKit1.ImageHandle != 0) 
			{
				
				ImageKit1.PrintDraw.ClearProperty();
				ImageKit1.PrintDraw.PenMode = IMAGEKIT7Lib.PenModeConstants.ikPenModeNotXorPen;
				ImageKit1.PrintDraw.PenWidth = 2;
				ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
				ret = ImageKit1.PrintDraw.Ellipse(ImageKit1.hDC, e.x - 2, e.y - 2, e.x + 2, e.y + 2, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikScreen);
			}
		}

		private void ImageKit2_MouseDownEvent(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseDownEvent e)
		{
			bool ret;
			if (ImageKit2.ImageHandle != 0)
			{
				ImageKit1.PrintDraw.ClearProperty();
				ImageKit1.PrintDraw.PenMode = IMAGEKIT7Lib.PenModeConstants.ikPenModeNotXorPen;
				ImageKit1.PrintDraw.PenWidth = 2;
				ImageKit1.PrintDraw.PenStyle = IMAGEKIT7Lib.PenStyleConstants.ikPenSolid;
				ret = ImageKit1.PrintDraw.Ellipse(ImageKit2.hDC, e.x - 2, e.y - 2, e.x + 2, e.y + 2, IMAGEKIT7Lib.OutPutDeviceModeConstants.ikScreen);
			}
			
		}
		private void Disp()
		{
			if (PointNum == 0){Label1.Text = "Set the start point on the left image.";}
			if (PointNum == 1){Label1.Text = "Set the end point on the left image.";}
			if (PointNum == 2){Label1.Text = "Set the start point on the right image.";}
			if (PointNum == 3){Label1.Text = "Set the end point on the right image.";}
			if (PointNum == 4){Label1.Text = "Click the Execute button";}
		}

		private void ImageKit2_MouseDownImage(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseDownImageEvent e)
		{
			Disp();
			if (PointNum == 2) 
			{
				xR1 = e.x;
				yR1 = e.y;
			}

			if (PointNum == 3) 
			{
				xR2 = e.x;
				yR2 = e.y;
			}
            

			PointNum = PointNum + 1;
			Disp();
		}

		private void ImageKit1_MouseDownImage(object sender, AxIMAGEKIT7Lib._IImageKitEvents_MouseDownImageEvent e)
		{
			 Disp();
			if (PointNum == 0) 
			{
				xL1 = e.x;
				yL1 = e.y;
			}

			if (PointNum == 1) 
			{
				xL2 = e.x;
				yL2 = e.y;
			}
            

			PointNum = PointNum + 1;
			Disp();
		}
	}
}
