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 Command9;
		public System.Windows.Forms.Button Command8;
		public System.Windows.Forms.Button Command7;
		public System.Windows.Forms.Button Command6;
		public System.Windows.Forms.Button Command5;
		public System.Windows.Forms.Button Command4;
		public System.Windows.Forms.Button Command3;
		public System.Windows.Forms.Button Command2;
		public System.Windows.Forms.Button Command1;
		public System.Windows.Forms.GroupBox Frame1;
		public System.Windows.Forms.GroupBox Frame2;
		public System.Windows.Forms.GroupBox Frame3;
		public System.Windows.Forms.TextBox Text1;
		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>
		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.Command9 = new System.Windows.Forms.Button();
			this.Command8 = new System.Windows.Forms.Button();
			this.Command7 = new System.Windows.Forms.Button();
			this.Command6 = new System.Windows.Forms.Button();
			this.Command5 = new System.Windows.Forms.Button();
			this.Command4 = new System.Windows.Forms.Button();
			this.Command3 = new System.Windows.Forms.Button();
			this.Command2 = new System.Windows.Forms.Button();
			this.Command1 = new System.Windows.Forms.Button();
			this.Frame1 = new System.Windows.Forms.GroupBox();
			this.Frame2 = new System.Windows.Forms.GroupBox();
			this.Frame3 = new System.Windows.Forms.GroupBox();
			this.Text1 = new System.Windows.Forms.TextBox();
			this.ImageKit1 = new AxIMAGEKIT7Lib.AxImageKit();
			((System.ComponentModel.ISupportInitialize)(this.ImageKit1)).BeginInit();
			this.SuspendLayout();
			// 
			// Command9
			// 
			this.Command9.BackColor = System.Drawing.SystemColors.Control;
			this.Command9.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command9.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command9.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command9.Location = new System.Drawing.Point(504, 376);
			this.Command9.Name = "Command9";
			this.Command9.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command9.Size = new System.Drawing.Size(97, 37);
			this.Command9.TabIndex = 23;
			this.Command9.Text = "Save Image to File";
			this.Command9.Click += new System.EventHandler(this.Command9_Click);
			// 
			// Command8
			// 
			this.Command8.BackColor = System.Drawing.SystemColors.Control;
			this.Command8.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command8.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command8.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command8.Location = new System.Drawing.Point(504, 336);
			this.Command8.Name = "Command8";
			this.Command8.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command8.Size = new System.Drawing.Size(97, 33);
			this.Command8.TabIndex = 22;
			this.Command8.Text = "Modify Image Data";
			this.Command8.Click += new System.EventHandler(this.Command8_Click);
			// 
			// Command7
			// 
			this.Command7.BackColor = System.Drawing.SystemColors.Control;
			this.Command7.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command7.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command7.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command7.Location = new System.Drawing.Point(504, 272);
			this.Command7.Name = "Command7";
			this.Command7.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command7.Size = new System.Drawing.Size(97, 33);
			this.Command7.TabIndex = 19;
			this.Command7.Text = "Draw Ellipse";
			this.Command7.Click += new System.EventHandler(this.Command7_Click);
			// 
			// Command6
			// 
			this.Command6.BackColor = System.Drawing.SystemColors.Control;
			this.Command6.Cursor = System.Windows.Forms.Cursors.Default;
			this.Command6.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Command6.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Command6.Location = new System.Drawing.Point(504, 232);
			this.Command6.Name = "Command6";
			this.Command6.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command6.Size = new System.Drawing.Size(97, 33);
			this.Command6.TabIndex = 18;
			this.Command6.Text = "Draw Text";
			this.Command6.Click += new System.EventHandler(this.Command6_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(504, 192);
			this.Command5.Name = "Command5";
			this.Command5.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command5.Size = new System.Drawing.Size(97, 33);
			this.Command5.TabIndex = 17;
			this.Command5.Text = "Use Pen";
			this.Command5.Click += new System.EventHandler(this.Command5_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(504, 112);
			this.Command4.Name = "Command4";
			this.Command4.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command4.Size = new System.Drawing.Size(97, 33);
			this.Command4.TabIndex = 16;
			this.Command4.Text = "Redisplay Toolbar";
			this.Command4.Click += new System.EventHandler(this.Command4_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(504, 72);
			this.Command3.Name = "Command3";
			this.Command3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command3.Size = new System.Drawing.Size(97, 33);
			this.Command3.TabIndex = 15;
			this.Command3.Text = "Hide Toolbar";
			this.Command3.Click += new System.EventHandler(this.Command3_Click);
			// 
			// 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(488, 432);
			this.Command2.Name = "Command2";
			this.Command2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command2.Size = new System.Drawing.Size(129, 33);
			this.Command2.TabIndex = 14;
			this.Command2.Text = "End";
			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(488, 16);
			this.Command1.Name = "Command1";
			this.Command1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Command1.Size = new System.Drawing.Size(129, 33);
			this.Command1.TabIndex = 13;
			this.Command1.Text = "Load Image from File";
			this.Command1.Click += new System.EventHandler(this.Command1_Click);
			// 
			// Frame1
			// 
			this.Frame1.BackColor = System.Drawing.SystemColors.Control;
			this.Frame1.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame1.Location = new System.Drawing.Point(488, 160);
			this.Frame1.Name = "Frame1";
			this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame1.Size = new System.Drawing.Size(129, 152);
			this.Frame1.TabIndex = 20;
			this.Frame1.TabStop = false;
			this.Frame1.Text = "Some Edit Functions";
			// 
			// Frame2
			// 
			this.Frame2.BackColor = System.Drawing.SystemColors.Control;
			this.Frame2.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Frame2.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame2.Location = new System.Drawing.Point(488, 56);
			this.Frame2.Name = "Frame2";
			this.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame2.Size = new System.Drawing.Size(129, 97);
			this.Frame2.TabIndex = 21;
			this.Frame2.TabStop = false;
			this.Frame2.Text = "Displaying Toolbar";
			// 
			// Frame3
			// 
			this.Frame3.BackColor = System.Drawing.SystemColors.Control;
			this.Frame3.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Frame3.ForeColor = System.Drawing.SystemColors.ControlText;
			this.Frame3.Location = new System.Drawing.Point(488, 320);
			this.Frame3.Name = "Frame3";
			this.Frame3.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.Frame3.Size = new System.Drawing.Size(129, 105);
			this.Frame3.TabIndex = 24;
			this.Frame3.TabStop = false;
			this.Frame3.Text = "Saving Changes";
			// 
			// 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(473, 80);
			this.Text1.TabIndex = 25;
			this.Text1.Text = @"A lot of people have asked if the editing toolbar functions can be used programatically. Unfortunately, the image editing toolbars must be displayed for their edit functions to be enabled. This sample illustrates a work around where the toolbar is hidden from view and the edit functions are used programatically. In this sample we set just a few properties for the pen and also for drawing text and ellipse. This sample includes a readme text.";
			// 
			// ImageKit1
			// 
			this.ImageKit1.Location = new System.Drawing.Point(8, 88);
			this.ImageKit1.Name = "ImageKit1";
			this.ImageKit1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("ImageKit1.OcxState")));
			this.ImageKit1.Size = new System.Drawing.Size(472, 376);
			this.ImageKit1.TabIndex = 26;
			this.ImageKit1.SelEditFunc += new AxIMAGEKIT7Lib._IImageKitEvents_SelEditFuncEventHandler(this.ImageKit1_SelEditFunc);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(621, 470);
			this.Controls.Add(this.ImageKit1);
			this.Controls.Add(this.Text1);
			this.Controls.Add(this.Command9);
			this.Controls.Add(this.Command8);
			this.Controls.Add(this.Command7);
			this.Controls.Add(this.Command6);
			this.Controls.Add(this.Command5);
			this.Controls.Add(this.Command4);
			this.Controls.Add(this.Command3);
			this.Controls.Add(this.Command2);
			this.Controls.Add(this.Command1);
			this.Controls.Add(this.Frame1);
			this.Controls.Add(this.Frame2);
			this.Controls.Add(this.Frame3);
			this.Name = "Form1";
			this.Text = "Hiding the Image Editing Toolbars";
			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 Command1_Click(object sender, System.EventArgs e)
		{
			//display the "Open" file dialog...
			if (ImageKit1.File.OpenFileDialog() == false) 
			{
				return;
			}
		
			//Load the image file...
			ImageKit1.File.LoadFile(IMAGEKIT7Lib.LoadFileConstants.ikLoad);
		
			//Just to simplify things I am making sure a raster image is loaded...
			if (ImageKit1.ImageKind != IMAGEKIT7Lib.ImageKindConstants.ikRasterImage) 
			{
				MessageBox.Show("Please load a raster image.");
				return;
			}
		
			ImageKit1.ScrollBar=true;
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikActualSize);
		}

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

		private void Command3_Click(object sender, System.EventArgs e)
		{
			ImageKit1.Edit.ToolBarLeft = -1000;
		}

		private void Command4_Click(object sender, System.EventArgs e)
		{
			ImageKit1.Edit.ToolBarLeft = 50;
		}

		private void Command5_Click(object sender, System.EventArgs e)
		{
			//set the pen size...
			ImageKit1.Edit.PenSize = IMAGEKIT7Lib.PenSizeConstants.ikPenSize1;
			ImageKit1.Edit.PenSize3 = 50;
		
			//set the edit action to the pen...
			ImageKit1.Edit.Action = IMAGEKIT7Lib.SelEditFuncConstants.ikPen;
		}

		private void Command6_Click(object sender, System.EventArgs e)
		{
			//set some text properties...
			ImageKit1.Edit.FontName = "Arial";
			ImageKit1.Edit.FontBold = false;
			ImageKit1.Edit.FontItalic = false;
			ImageKit1.Edit.FontSize = 16;
		
			//set the action to the text tool...
			ImageKit1.Edit.Action = IMAGEKIT7Lib.SelEditFuncConstants.ikText;
		
			//clear the edit's text property...
			ImageKit1.Edit.Text = "";
		}

		private void Command7_Click(object sender, System.EventArgs e)
		{
			//set the pen size...
			ImageKit1.Edit.PenSize = IMAGEKIT7Lib.PenSizeConstants.ikPenSize3;
			ImageKit1.Edit.PenSize3 = 5;
		
			//set the edit action to the ellipse...
			ImageKit1.Edit.Action = IMAGEKIT7Lib.SelEditFuncConstants.ikEllipse;
		}

		private void Command8_Click(object sender, System.EventArgs e)
		{
			ImageKit1.Edit.Modify();
		}

		private void Command9_Click(object sender, System.EventArgs e)
		{
			//exit if there is no image loaded...
			if (ImageKit1.ImageHandle == 0) 
			{
				return;
			}		
			//set the file extensions that are displayed in the "Save" file dialog.
			ImageKit1.File.FileExt = "*;BMP;JPG;GIF;";
			/*---------------------------------------------------------------------------
			// IMPORTANT: The asterik "*" in the FileExt property removes the "All Files"
			// option from the "Save" file dialog. THIS IS NECESSARY WHEN SAVING FILES
			// using the SaveFileDlgFileType property because it returns 0 if "All Files"
			// is selected...
			---------------------------------------------------------------------------
			*/
		
			//display the "Save" file dialog...
			if (ImageKit1.File.SaveFileDialog() == false)
			{
				return;
			}

			//use the value of the SaveFileDlgFileType to determine the SaveFile method...
			switch (ImageKit1.File.SaveFileDlgFileType)
			{
			
				case IMAGEKIT7Lib.SaveFileDlgFileTypeConstants.ikSaveDlgBMP:
					//save as uncompressed bmp...
					ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveBMP, 0);
					break;
				
				case IMAGEKIT7Lib.SaveFileDlgFileTypeConstants.ikSaveDlgJPEG:
					//save as jpeg. Must check the bitcount and don't forget the JpegQuality!
					if (ImageKit1.BitCount == 24) 
					{
						ImageKit1.File.JpegQuality = 70;
						ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveJPEG, 0);
					}
					else if (ImageKit1.BitCount == 8) 
					{
						if (ImageKit1.Gray != false) 
						{
							ImageKit1.File.JpegQuality = 70;
							ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveJPEG, 0);
						}
					}

					else 
					{
						MessageBox.Show("Jpeg images must be 24 bit color or 8 bit grayscale");
						return;
					}
					break;
				
				case IMAGEKIT7Lib.SaveFileDlgFileTypeConstants.ikSaveDlgGIF:
					//save as gif. Must check the bitcount!
					if (ImageKit1.BitCount > 8) 
					{
						MessageBox.Show("Gif images must be 256 colors or less");
						return;
					}
					ImageKit1.File.SaveFile(IMAGEKIT7Lib.SaveFileConstants.ikSaveGIF, 0);
					break;
			}
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			int BlankImageHandle;
		
			//create an image when the form loads so that the tools can be used without having to load any other images...
		
			BlankImageHandle = ImageKit1.CreateImage(480, 400, 24, 255, 255, 255);
			ImageKit1.ImageHandle = BlankImageHandle;
			ImageKit1.ScrollBar=true;
			ImageKit1.Display(IMAGEKIT7Lib.DispModeConstants.ikActualSize);
		
			//enable and display the raster image editing toolbar...
			ImageKit1.Edit.EditEnable = true;
			ImageKit1.Edit.ToolBarCloseBox = true;
			ImageKit1.Edit.ToolBarCaption = "Edit";
			ImageKit1.Edit.ToolBarLeft = 50;
			ImageKit1.Edit.ToolBarTop = 50;
			ImageKit1.Edit.ShowToolBar(IMAGEKIT7Lib.EditToolBarModeConstants.ikRaster);
		}

		private void ImageKit1_SelEditFunc(object sender, AxIMAGEKIT7Lib._IImageKitEvents_SelEditFuncEvent e)
		{
			//set the cursors for each editing function...
			if (e.selFunction == IMAGEKIT7Lib.SelEditFuncConstants.ikPen) 
			{
				ImageKit1.MouseCursorFile = Application.StartupPath + @"\..\..\PENCIL.CUR";
				ImageKit1.MouseCursorType = IMAGEKIT7Lib.CursorTypeConstants.ikCursorCustom;
			}
			else if (e.selFunction == IMAGEKIT7Lib.SelEditFuncConstants.ikEllipse) 
			{
				ImageKit1.MouseCursorFile = Application.StartupPath + @"\..\..\DRAGMOVE.CUR";
				ImageKit1.MouseCursorType = IMAGEKIT7Lib.CursorTypeConstants.ikCursorCustom;
			}
			
			else if (e.selFunction == IMAGEKIT7Lib.SelEditFuncConstants.ikText) 
			{
				ImageKit1.MouseCursorFile = Application.StartupPath + @"\..\..\H_POINT.CUR";
				ImageKit1.MouseCursorType = IMAGEKIT7Lib.CursorTypeConstants.ikCursorCustom;
			}
			else 
			{
				ImageKit1.MouseCursorType = IMAGEKIT7Lib.CursorTypeConstants.ikCursorARROW;
			}
		}
	}
}
